EchoFool Posted September 10, 2008 Share Posted September 10, 2008 Hey, I need help with an array that i want to insert into a table.. The table has 6 fields just named "one" "two" "three" "four" "five" "six". Now with my array i have sorted the numbers in order and now i want to insert it into the database in that order so "one" will have lowest and "six" will have the highest. But i do not know how to do it.. and it should be one row so a while loop for the array won't work because it'll insert 6 rows. This is what i have: <?php //create array etc // get numbers from form etc // put then numbers into the array etc // ------------------- //below is the array sorting sort($numbers); $check = false; $skip = false; foreach ($numbers as $next) { if ($next == trim($check)) { $skip = 1; } $check = $next; } If($skip){ ?> Duplicate number inserted! <?php } ?> Any suggestions on how i can achieve what im trying to do ? I've hit a brick wall on this one. Link to comment https://forums.phpfreaks.com/topic/123687-solved-array-inserting-help/ Share on other sites More sharing options...
sasa Posted September 10, 2008 Share Posted September 10, 2008 $sql ="INSERT INTO table_name (one,two,three,four,five,six) VALUES (" . implode(',',$numbers) . ")"; Link to comment https://forums.phpfreaks.com/topic/123687-solved-array-inserting-help/#findComment-638698 Share on other sites More sharing options...
EchoFool Posted September 10, 2008 Author Share Posted September 10, 2008 Ok thank you, I tried it though having problems with my ' and " not sure where i should and should not use them, this is what i got: <?php $INSERT = myslq_query('INSERT INTO tabl_nums (UserID,Number1,Number2,Number3,Number4,Number5,Number6,BoughtOn) VALUES ('{$_SESSION['Current_User']'," . implode(',',$numbers) . ",'$On')') Or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/123687-solved-array-inserting-help/#findComment-638707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.