Can anyone tell me why my insert statement in the loop is only inserting the first record? The code completes 5 trips through the loop and it is selecting different sets each time through (I can see the sets with the echo at the end of the loop), but it only inserts the first set.
Code:
$count = 0;
While ($count < 10){
$sql= "SELECT id
FROM quest
WHERE used = '0'
ORDER BY RAND()
LIMIT 1";
$results = mysqli_query($con,$sql);
while ($row=mysqli_fetch_array($results)){
$id = $row['id'];
}
$mark = "UPDATE quest
SET used = '1'
WHERE id = '$id'";
mysqli_query($con,$mark);
$sql2= "SELECT id
FROM quest
WHERE used = '0'
ORDER BY RAND()
LIMIT 1";
$results2 = mysqli_query($con,$sql2);
while ($row=mysqli_fetch_array($results2)){
$id2 = $row['id'];
}
$mark2 = "UPDATE quest
SET used = '1'
WHERE id = '$id2'";
mysqli_query($con,$mark2);
$build = "INSERT INTO holding
(q1,q2) VALUES ('$id','$id2')";
mysqli_query($con,$build);
echo $id;
echo $id2;
echo "<br>";
$count = $count + 2;
}
mysqli_close($con);