View Full Version : Insert into table SET question

11-22-2002, 09:44 AM
I have a question regarding the INSERT command, specifically, inserting sets of data. As an example:

$sql="insert into thebooks set

I noticed that the variable $temp contains only the data it was set to when the page first loaded, and in a for loop querying the above multiple times, even if I change $temp, the data that gets inserted remains that of the original $temp content.

My question are:

1) Is there a way to make the above query dynamic in the sense that variable $temp will be dynamically evalulated?
2) Also, what's the syntax to assigning a 2 dimensional array in place of $temp above? For example:


The above doesn't work.


11-24-2002, 11:56 AM
Is it just me or is that a tad confusing?

As far as I have learned 'SET' is either for changing the server operation options or for use in UPDATE queries. If you are only inserting data into your database, lose the set part of the query...

$sql = "INSERT INTO `thebooks`
(Bookname,Bookimage,Bookurl) VALUES

If you wanted to overwrite an old row, use UPDATE `thebooks` SET ...... WHERE a='b'

Any chance you could give a quick idea of the array setup that you are trying to insert?
You are possibly going to be wanting to eval the value of your inserted data from an array, just would be heaps easier to help if we knew where the data is coming from and in what format it is reaching the query

a quicky eg

$temp[0] = array("TLOTR","hobbit.jpg","http:tolkien")
$temp[1] = array("CITR","holden.jpg","http:salinger")

would be easy as you could just increment the $temp[index] and attribute known second dimension indices.

$temp_index = -1;
while(++$temp_index < count($temp))
$quiz = "INSERT INTO `thebooks`
(Bookname,Bookimage,Bookurl) VALUES

Last note: Your multidimensional syntax should be fine, as long as you have an index in $temp[0] named test
$temp[0] = array( test => "7", retest => "12")

11-24-2002, 12:05 PM
Subnote [after waking up a tad more] - you might find your multi-dim query would need the double quotes escaped (perhaps). Plus I sorta worked out what SET does in an insert :)

11-26-2002, 12:57 PM
Hi Íkii:
Thanks for the interesting info. I'm still just experimenting with sql commands, so my questions are bound to be confusing. I've yet to have time to try out anything since my post above; I'll update this thread when I get to it again :)