I want to show A result which requires Two previous queries; and as I am trying to do this stuff with the new Mysqli interface, I don’t get it to work in the right way.
I have this, and the output is: Warning: mysqli::prepare() [mysqli.prepare]: All data must be fetched before a new statement prepare takes place
$qryRdmPh="SELECT `id` FROM `table` ORDER BY RAND() LIMIT 0,30";
$stmtRdmPh = $mysqli->prepare($qryRdmPh);
$stmtRdmPh->execute();
$stmtRdmPh->bind_result($id);
while($stmtRdmPh->fetch()) {
//Obtener el atributo Frase
$qryPhVal="SELECT `id_v` FROM `values` WHERE `id_p`='" . $id . "'";
$stmtPhVal = $mysqli->prepare($qryPhVal);
$stmtPhVal->execute();
$stmtPhVal->bind_result($idV);
while($stmtPhVal->fetch()){
echo $idV;
}
}
There must be another way to show results without so complex rules… I’ve read it’s very important to use Statement queries, but why? It makes my code just much longer and more complex.
Edit: I would really thank if someone explains me if statements are so important as said, and if I should use them always.
There is always a possibility to do the same thing without nesting queries in this way. And what’s more… if you are doing it this way, it may harm your DB. Always try to get a simplier way.
For example: If you want to do queries which depend on a current query, it would be better if you make a buffer and insert all rows after buffering.