PDA

Click to See Complete Forum and Search --> : [RESOLVED] insert inside while loop !!!


samsyl
Jun 1st, 2009, 06:37 AM
how can i write a insert command inside a while loop ?
i did try like following code but its not working !!!


while($result=mysql_fetch_array($sql))
{
mysql_query(INSERT INTO ......);
}

manavo11
Jun 1st, 2009, 10:25 AM
Is the problem with the loop or the actual query? What are you trying to do? Also the condition in the loop looks wrong.

You run the query to get the results. Then you loop through the results to get the rows. So you should probably have something like this:

$Query = "Some SELECT query here";
$ResultSet = mysql_query($Query);
while ($Row = mysql_fetch_array($ResultSet)) {
//do stuff here
}

samsyl
Jun 2nd, 2009, 08:23 AM
thanks a lot for this tips. it was helpfull