Jump to content

Display mysql table data on a php webpage


DayDreamer16

Recommended Posts

if you just want to display your data in a table then this should work just change it so it works with your database

 

<?php
$con = mysql_connect("host","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database_name", $con);

$result = mysql_query("SELECT * FROM table");
echo "<table border='1'>
<tr>
<th>name</th>
<th>number</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['number'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>

Here is an example of a table I have working atm.

 

echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"15\">";
echo "<tr>";
$i=0;
while ($i < $num) {

$skillname = mysql_result($result,$i,"skillname");
$class = mysql_result($result,$i,"class");
$type = mysql_result($result,$i,"type");
$description = mysql_result($result,$i,"description");
$name = mysql_result($result,$i,"name");
echo "<tr>\n";
echo "<td>";
echo "<hr>";
echo "<b>Skillname:  </b>$skillname<br>";
echo "<b>Class:  </b>$class<br>";
echo "<b>Skill Type:  </b>$type<br>";
echo "<b>Description:</b>$description<br>";
echo "<b>Submitted by:  </b>$name<br>";
echo "<hr>";
echo "</td>";
$i++;
}
echo "</table>";

 

 

Hope that helps a little.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.