spacepoet Posted January 11, 2012 Share Posted January 11, 2012 Hello: I am writing this code: <?php include('include/myConn.php'); include('include/myCodeLib.php'); $zip_id = $_REQUEST['zip_id']; $query=mysql_query("SELECT zip_id,city,full_state,zip FROM zip_codes WHERE zip_id = $zip_id") or die("Could not get data from db: ".mysql_error()); while($result=mysql_fetch_array($query)) { $zip_id=$result['zip_id']; $city=$result['city']; $full_state=$result['full_state']; $zip=$result['zip']; } ?> <!DOCTYPE HTML> <head> <title></title> </head> <body> <?php echo $city; ?>, <?php echo $full_state; ?> <?php echo $zip; ?> </body> </html> It works fine as far as writing out the "City, State Zipcode", but I wanted to see if there is a way to "join" the 3 statements together so it can be written as just 1 statement. Like: <?php echo $city, $full_state $zip; ?> What is the trick to doing this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/254771-join-3-php-statements-into-1/ Share on other sites More sharing options...
mrdhood Posted January 11, 2012 Share Posted January 11, 2012 echo "City: " . $city . "; Full State: " . $full_state . "; Zip: " . $zip; The . continues it. Quote Link to comment https://forums.phpfreaks.com/topic/254771-join-3-php-statements-into-1/#findComment-1306350 Share on other sites More sharing options...
spacepoet Posted January 11, 2012 Author Share Posted January 11, 2012 OK, thank you. I think I see where you are going with it. Something like: <?php echo . $city . " ," . $full_state . $zip . ?> ??? I basically want it to read "City, State Zipcode" Example: Downingtown, Pennsylvania 19335 Will that work that way? Quote Link to comment https://forums.phpfreaks.com/topic/254771-join-3-php-statements-into-1/#findComment-1306629 Share on other sites More sharing options...
KevinM1 Posted January 11, 2012 Share Posted January 11, 2012 Easier to just: <?php echo "$city, $full_state $zip"; ?> Placing variables in double-quoted strings will echo their values. Quote Link to comment https://forums.phpfreaks.com/topic/254771-join-3-php-statements-into-1/#findComment-1306638 Share on other sites More sharing options...
spacepoet Posted January 12, 2012 Author Share Posted January 12, 2012 Excellent! Thank you very much. Just what I was looking for. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254771-join-3-php-statements-into-1/#findComment-1306758 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.