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);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.