Ok so I’m trying to make a localhost site that has the same base functions as Phpmyadmin, and everything is working other than displaying a table’s data.
here’s an example of what I’m trying to accomplish:
though I’m not sure how to accomplish this. Here is some code to show you what I have now
<div class="content">
<?php $query2 = "SELECT * FROM " . $table; ?>
<div class="query-class">
<?php echo $query2; ?>
</div>
<h1>
Tables In <?php echo $db; ?>
</h1>
<table>
<?php
$columquery = "SHOW COLUMNS FROM " . $table;
$columresult = mysql_query($columquery);
while ($row3 = mysql_fetch_array($columresult)) {
echo "<th>" . $row3['Field'] . "</th>";
}
?>
<?php
$result2 = mysql_query($query2);
while ($row2 = mysql_fetch_array($result2)) {
foreach($row2 as $var) {
echo "<tr><td>" . $var . "</td></tr>";
}
}
?>
</table>
</div>
Yes yes, I know it’s horrible.
4
Answers
I think you are looking for something very ugly like the following. I found it in the garbage. I am not responsable for any use of it:
Db is an standard singleton that contains a mysqli private object.
query() contains something like
to create the “array of arrays” response. Suitable for the output you are looking for.
If i understood you well, You need mysqli_fetch_row.
I’ve added some escaping and only queried the database when needed:
Hope this helps,
The other answers use the
mysqli
API while you’re using the older, no longer supportedmysql
API. I really recommend upgrading to eithermysqli
orPDO
, but if you want to stay withmysql
you can use the following solution: