Forum Moderators: coopster

Message Too Old, No Replies

Multiple INSERT on single table

         

maxxtraxx

1:44 am on May 15, 2003 (gmt 0)

10+ Year Member



hi all,

i have a page on a scheduling system that i'm creating that i need to insert several records on the same table. to make it easy on the data entry person i would like to insert these records all at the same time. is there a way to do this in PHP?

for example: you have a single day that can have multiple entries (available times).

thanks in advance

Birdman

2:11 am on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes it can be done using arrays.

Example(HTML form):


<form action="insert_script.php">
<input type="text" name="name[]" />
<input type="text" name="date[]" />
<input type="text" name="time[]" />
<input type="submit" />
</form>

Example(insert_script.php):


<?php
for( $i=0; $i < count($name); $i++)
{
if ($name[$i] == "") continue;
sql .= "INSERT INTO tablename ( `name` , date` , `time`) VALUES ('$name[$i]', '$date[$i]', '$time[$i]')";
}

mysql_query($sql) or die ("Something went wrong!");
?>

Play around with that and you should figure it out.

maxxtraxx

7:11 pm on May 15, 2003 (gmt 0)

10+ Year Member



ok, very interesting... so in my page i have several times that i want to insert a variable.

e.g. -

8:30AM - variable (0 - 3)
9:00AM - variable (0 - 3)
etc...

the variable is to select a status value (0 - 3) presented in a list/menu, so would i just name each list menu down the page, 'time1','time2', 'time3', etc? and then the loop in the script would pick that up or would i name each one just 'time'?