On 14-Jul-01 David wrote:
> I need to insert x amount of rows from one form.  The form displays x
> amount of rows.  I then need to insert the values from the form x amount
> of times.  The form loop works fine but how do I INSERT x amount of
> times within a loop from the values of the form?  I think I need to use
> some sort of array. I suck at arrays.
> 
> This executes when submit is hit:
> $i = 1;
> while ($i <= $songsinalbum) {
>  $query = "INSERT INTO songs VALUES ('$id',
> '$songname','$rating','$video', '$album_id', '$movie')";
>    $result = mysql_db_query("movies", $query);
> };
> 
> 

$vals='';
for ($i=0; $i<= $songsinalbum; $i++) {
  $vals .=", ('$songname[$i]', '$rating[$i]', '$video[$i]', '$album_id[$i]',
    '$movie[$i]')";
}

$vals=preg_replace('^,', '', $vals); // chop leading comma

$qry="INSERT INTO songs VALUES $vals";

// echo $qry, '<br>;

$res=mysql_query($qry);

 ...

> 
> Here is form:

<TD align="right">Songname:  </TD><TD><input type=text name='songname[]'
size=30><br></TD>
 <TD align="right">Rating:   </TD><TD><input type=text name='rating[]'


etc. 

Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to