I'm trying to execute a query inside a WHILE loop running on mysqli_fetch_array
. The query gives the following error:
Error: Commands out of sync; you can't run this command now
I found out that you can't have simultaneous queries. Here's my code
$query "SELECT * FROM table";
$exec = mysqli_query($con, $query);
while($loop = mysqli_fetch_array($exec)){
$data = $loop['data'];
$sim = "SELECT * FROM table2 WHERE col1 = '$data'";
$execsim = mysqli_query($con, $sim);
$getsim = mysqli_fetch_array($execsim);
$somedata = $getsim['somedata'];
//insert $somedata and $data into table3
}
After some research, I see that store_result()
could be useful here. Excuse my ignorance as this is new to me. There aren't any examples/solutions that I can find that use this with a WHILE loop scenario (does that make a difference?) - most are in object oriented style too.
What is the most effective way around this problem?
Aucun commentaire:
Enregistrer un commentaire