Reputation: 15
I'm currently having issues while trying to print a html table of SQL query results.
I currently have an sql query which requires an 'sid' which is stored as a local variable.
I'm trying to create a prepared statement which binds the $sid var to the query and create a while loop to loop through the data and print the results into a table.
Below, I have tried to create the code but it does not yet seem to work. Any help would be appreciated, Thanks
$sid = '166410';
$query = "SELECT enrl.ayr, enrl.status, prog.ptitle, enrl.lvl
FROM enrl, prog
WHERE enrl.sid =?
AND enrl.pid = prog.pid
ORDER BY lvl DESC";
$scap = '';
if ($st = mysqli_prepare($link, $query)) {
mysqli_stmt_execute($st);
mysqli_stmt_bind_param($st, "s", $sid);
mysqli_stmt_bind_result($st, $ayr, $status, $ptitle, $lvl);
while (mysqli_stmt_fetch($st)) {
$scap .= "
<table id=\"test\" style=\"width:100%\">
<tr>
<td> " . $ayr . " </td>
<td> " . $status . "</td>
<td> " . $ptitle . "</td>
<td> " . $lvl . "</td>
</tr>
</table>
";
} $st->free();
mysqli_stmt_close($st);
}
mysqli_close($link);
print($scap);
Upvotes: 1
Views: 504
Reputation: 5846
<?php
$sid = '166410';
$query = "SELECT enrl.ayr, enrl.status, prog.ptitle, enrl.lvl
FROM enrl, prog
WHERE enrl.sid =?
AND enrl.pid = prog.pid
ORDER BY lvl DESC";
$scap = '';
$st = mysqli_prepare($link,$query);
mysqli_stmt_bind_param($st, "s", $sid);
mysqli_stmt_execute($st);
mysqli_stmt_bind_result($st, $ayr, $status, $ptitle, $lvl);
while (mysqli_stmt_fetch($st)) {
$scap .= "
<table id=\"test\" style=\"width:100%\">
<tr>
<td> " . $ayr . " </td>
<td> " . $status . "</td>
<td> " . $ptitle . "</td>
<td> " . $lvl . "</td>
</tr>
</table>
";
}
echo $scap;
mysqli_stmt_close($st);
mysqli_close($link);
?>
Upvotes: 1