View Full Version : how to show entries from mysql database
Hey.
I have a table with different information.
(item id, name, price)
How do i make a php document to output all the entries in the table on one document. (a list with the items)
eg.:
(item 1, coca cola, 1,00$
item 2, fanta, 1,00)
Im not shure what the sql and php code is?
please help :)
dardanel
07-26-2006, 07:54 PM
If you want just to print the records on each row ...you coud make something like this
if the table looks like this:
item fieldName price
item1 coca cola 1,00$
$query = "select * from tableName";
$request = mysql_query($query);
while($row = mysql_fetch_array($request))
{
print $row["item"].' '.$row["fieldName"].' $'.$row["price"]."\n";
}
This will print the record from the table row by row.
ill try that.. thank you so far
hmm it does come up, but very messy. im pretty new to the php, so im clueless. is it possible to make it alle arranged into a table, so it prints nicely on the site?
jr_yeo
07-26-2006, 08:50 PM
$query = "select * from tableName";
$request = mysql_query($query);
echo('<table border=1>');
while($row = mysql_fetch_array($request))
{
echo '<tr><td>' . $row["item"] . '</td>';
echo '<td>' . $row["fieldName"] . '</td>';
echo '<td>' . $row["price"] . '</td></tr>';
}
echo ('</table>');
i think :p
blm126
07-26-2006, 09:08 PM
That was close
$query = "select * from tableName";
$request = mysql_query($query);
echo('<table border=1>');
while($row = mysql_fetch_array($request))
{
echo '<tr>';
echo '<td>' . $row["item"] . '</td>';
echo '<td>' . $row["fieldName"] . '</td>';
echo '<td>' . $row["price"] . '</td>';
echo '</tr>';
}
echo ('</table>');
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.