Jump to content

[SOLVED] Array inserting help


EchoFool

Recommended Posts

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

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());
?>

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.