Jump to content

[SOLVED] Only displaying last result in array


hansman

Recommended Posts

code

$zips = $_POST['zips'];

$zipsextracted = explode(",", $zips);

mysql_connect("-----", "--------", "------");
mysql_select_db("--------") or die( "Unable to select database"); 
foreach($zipsextracted as $zip) {
"INSERT INTO `Zips_To_Company` (`id`, `company_id`, `zip_id`) VALUES ('', '1', '$zip')";
}

 

echo $zipsextracted; ------Displays "array"

 

when i turn the query into a variable it only shows the last item in the array.

Just a quick question just in case, are you actually running the query, as cant really tell from that code

 

 

i.e


$zips = $_POST['zips'];

$zipsextracted = explode(",", $zips);
mysql_connect("-----", "--------", "------");
mysql_select_db("--------") or die( "Unable to select database"); 
foreach($zipsextracted as $zip) {
$sql = "INSERT INTO `Zips_To_Company` (`id`, `company_id`, `zip_id`) VALUES ('', '1', '$zip')";
mysql_query($sql)or die('Error, insert query failed');
}

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.