Jump to content

Records inserted diagonally rather than across


clay1

Recommended Posts

This is related but a different issue than my other thread so I started a new topic

 

When I run my script, I am ending up with a table which looks like this:

 

a b c d

a NULL NULL NULL

NULL b NULL NULL

NULL NULL c NULL

 

$insertSql = "INSERT INTO test ($fields[$col]) VALUES ('$vars[$col]')";

		$result = pg_query($conn, $insertSql);

 

The echoed statement lines everything up correctly. Column A B C have the appropriate values and so forth

 

echo $insertSql;

Displays:

INSERT INTO test (a) VALUES ('a')INSERT INTO test (b) VALUES ('b')INSERT INTO test (c) VALUES ('c')

 

Each time it's moving down a row and over 1 column and inserting null values, instead of over each column and then down a row with the correct values.

 

I imagine this is somehow related to my loops, but can't figure out why it would echo correctly but not hit the DB correct

Just insert all same row values all at once.

 

"INSERT INTO `table` (`a`,`b`,`c`) VALUES ('a','b','c')";

// AKA

"INSERT INTO `table` (`$fields[$col]`,`$fields[$col+1]`,`$fields[$col+2]`) VALUES ('$fields[$col]','$fields[$col+1]','$fields[$col+2]')";

 

 

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.