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. Quote Link to comment 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) . ")"; Quote Link to comment 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()); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.