Jump to content

Join 3 PHP statements into 1 .. ??


spacepoet

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/254771-join-3-php-statements-into-1/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.