I have the following working code
$notchDetails = mysqli_query($conn, "SELECT * FROM notches WHERE projectid = ".$projectid." LIMIT ".$offset.", ".$limit."");
// i want $query here //
$outp3 = "[";
if (mysqli_num_rows($notchDetails) > 0) {
while($notch = mysqli_fetch_assoc($notchDetails)) {
$query = mysqli_query($conn, "DESCRIBE $table");
$count = count($notch);
$allnotches[] = $notch["notchid"]; // $allnotches is needed further in script //
if ($outp3 != "[") {$outp3 .= ",";}
$outp3 .= "{";
$x = 1;
while ($rs = mysqli_fetch_assoc($query)) {
$field = $rs["Field"];
$outp3 .= '"'.$field.'":"'.$notch[$field].'"';
if ($x != $count) { $outp3 .= ","; }
$x++;
}
$outp3 .= "}";
}
}
$outp3 .="]";
(Don't look at the var name notch, could'nt find a better translation than notch. Its complicated ;-) )
Problem explained:
When i place $query = mysqli_query...
outside the while loop (just under $notchDetails = mysqli_query...
),
it only gives 1 result and the rest is left empty in: while ($rs = mysqli_fetch_assoc($query)) { //result// }
Af far as i can see, it should work with the $query above the loop. But i don't understand why it is'nt.
Can someone explain me why this does'nt work?
P.s. The reason for placing it outside the loop is performance/speed