List:General Discussion« Previous MessageNext Message »
From:Don Read Date:July 14 2001 9:23pm
Subject:RE: Loop an INSERT from form
View as plain text  
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                                       dread@stripped
-- 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.
Thread
Loop an INSERT from formDavid14 Jul
  • Re: Loop an INSERT from formWerner Stuerenburg14 Jul
  • RE: Loop an INSERT from formDon Read14 Jul
    • Re: Loop an INSERT from formDavid15 Jul
Re: Loop an INSERT from formDavid15 Jul