Jump to content

display database in html table...


yanti

Recommended Posts

:-[

pls check on this code....it doesnt display any data from database...

 

<?php include('/include/dbConnection.php'); 
$result = mysql_query("SELECT * FROM ucapan ORDER BY datetime");
while($row = mysql_fetch_array($result))
?>
  <tr>
    <td><?php echo $row['id'] ?> </td>
    <td><?php echo $row['datetime'] ?> </td>
    <td><?php echo $row['ucapan'] ?> </td>
    <td><?php echo $row['sender'] ?> </td>
  </tr>
</table>
<? mysql_close($con);?>

 

this is code to display

 

below is code for html table

<body>
<table width="100%" border="1" class="InternalHeader">
  <tr>
    <td>LIST OF SMS UCAPAN</td>
    <td> </td>
  </tr>
</table>
<p> </p>
<table width="100%" border="1" class="NormalTableTwo">
  <tr>
    <td>NO</td>
    <td>DATE TIME</td>
    <td>UCAPAN</td>
    <td>SENDER</td>
  </tr>

 

Link to comment
https://forums.phpfreaks.com/topic/167084-display-database-in-html-table/
Share on other sites

You should use braces around looping part:

<?php include('/include/dbConnection.php'); 
$result = mysql_query("SELECT * FROM ucapan ORDER BY datetime");
while($row = mysql_fetch_array($result))
{  //   <-------------
?>
  <tr>
    <td><?php echo $row['id'] ?> </td>
    <td><?php echo $row['datetime'] ?> </td>
    <td><?php echo $row['ucapan'] ?> </td>
    <td><?php echo $row['sender'] ?> </td>
  </tr>
</table>
<?php 
}  //   <-------------
mysql_close($con);?>

Then check is your query gives any result at all:

 

<?php include('/include/dbConnection.php'); 
if($result = mysql_query("SELECT * FROM ucapan ORDER BY datetime"))
{
while($row = mysql_fetch_array($result))
{  
?>
  <tr>
    <td><?php echo $row['id'] ?> </td>
    <td><?php echo $row['datetime'] ?> </td>
    <td><?php echo $row['ucapan'] ?> </td>
    <td><?php echo $row['sender'] ?> </td>
  </tr>
</table>
<?php 
}  //   <-------------
} else
{
echo "error";

}
mysql_close($con);?>

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.