Question : Loop to insert data into mysql table

I have some values in post like:

$ob1=$_POST['ob1'];
$ob2=$_POST['ob2'];
$ob3=$_POST['ob3'];
----------------------upto 30-----------
$ob50=$_POST['ob50'];

first i want to add loop to make code short.

now i use code to insert these value to table:


$query1= mysql_query("INSERT INTO squestions(obno, ucode)
VALUES
('$ob1','$testcode')");


$query2= mysql_query("INSERT INTO squestions(obno, ucode)
VALUES
('$ob2','$testcode')");


$query3= mysql_query("INSERT INTO squestions(obno, ucode)
VALUES
('$ob3','$testcode')");


-------------upto 50 queries----------------


$query50= mysql_query("INSERT INTO squestions(obno, ucode)
VALUES
('$ob50','$testcode')");


Please help me ,
how to add loop for this?





Answer : Loop to insert data into mysql table

Sorry I've given you a bit of a bum steer.

'ob'.$counter not 'ob$counter'
1:
2:
3:
4:
5:
6:
7:
8:
9:
for ( $counter = 1; $counter <= 50; $counter++)
{
  if ($_POST['ob'.$counter]>'')
  {
    $ob=$_POST['ob'.$counter];
    mysql_query("INSERT INTO squestions(obno, ucode)
      VALUES ('$ob','$testcode')");
  }
}
Random Solutions  
 
programming4us programming4us