hansman Posted August 22, 2008 Share Posted August 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/120876-solved-only-displaying-last-result-in-array/ Share on other sites More sharing options...
DarkWater Posted August 22, 2008 Share Posted August 22, 2008 You can't echo an array to begin with, so it just shows "Array" when you try to echo it. Now, what happens with the query exactly, and how is $_POST['zips'] formatted? Link to comment https://forums.phpfreaks.com/topic/120876-solved-only-displaying-last-result-in-array/#findComment-623069 Share on other sites More sharing options...
hansman Posted August 22, 2008 Author Share Posted August 22, 2008 $_POST['zips'] = 10567,10567...... and the query dosent even work, nothing put into the db Link to comment https://forums.phpfreaks.com/topic/120876-solved-only-displaying-last-result-in-array/#findComment-623071 Share on other sites More sharing options...
hansman Posted August 22, 2008 Author Share Posted August 22, 2008 $_POST['zips'] = 10567,10567...... and the query dosent even work, nothing put into the db Link to comment https://forums.phpfreaks.com/topic/120876-solved-only-displaying-last-result-in-array/#findComment-623072 Share on other sites More sharing options...
Jibberish Posted August 22, 2008 Share Posted August 22, 2008 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'); } Link to comment https://forums.phpfreaks.com/topic/120876-solved-only-displaying-last-result-in-array/#findComment-623075 Share on other sites More sharing options...
hansman Posted August 22, 2008 Author Share Posted August 22, 2008 haha im stupid forgot to query it, thank you Link to comment https://forums.phpfreaks.com/topic/120876-solved-only-displaying-last-result-in-array/#findComment-623080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.