Jump to content

[SOLVED] Query DB and split results between two arrays


siamiam

Recommended Posts

This is the code I currently have.

 

$result = mysql_query("SELECT DISTINCT city, state FROM exp_weblog_data");

while($row = mysql_fetch_array($result))
  {
  echo $row['city'] . ", " . $row['state'];
  echo "<br />";
  }

 

It outputs something "New York, NY".

 

I need to take that information a split it between two arrays like the following (for an autosuggest script)...

 

 

$city = array(
	"New York",
	"Los Angeles",
                "Miami"

);

$state = array(
	"NY",
	"CA",
                "FL"
);

 

 

I've been going in circles trying to figure it out on my own.

 

Any direction would be greatly appreciated. Thanks

$result = mysql_query("SELECT DISTINCT city, state FROM exp_weblog_data");

while($row = mysql_fetch_array($result))
{
    echo $row['city'] . ", " . $row['state'];
    echo "<br />";
    $cities[] = $row['city'];
    $states[] = $row['state'];
}

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.