Jump to content

Not able to display data in table format in php


manjumadhav93

Recommended Posts

Sorry for the beginner question, here I'm trying to retrieve data from the database and display it in the table format. But only table headers are printed, and not the actual values. The count variable is echoing 2 saying that data is present and correctly retrieved. Can anyone help?

<?php
include 'connect.php';
error_reporting(E_ALL ^ E_DEPRECATED);
error_reporting(E_ERROR | E_PARSE);
$sql="SELECT * FROM `resources` as r INNER JOIN `project_resources` as pr
ON r.res_id =pr.res_id WHERE project_id='$_POST[project_id]'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($result === FALSE) {
die(mysql_error()); 
}
echo "$count";
echo '<table>
<tr>
<th>Resource ID</th>
<th>Resource Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Reporting Manager</th>
<th>Role</th>
<th>Designation</th>
</tr>';

while ($row = mysql_fetch_array($result)) {
echo '
<tr>
<td>'.$row['res_id'].'</td>
<td>'.$row['res_name'].'</td>
<td>'.$row['email'].'</td>
<td>'.$row['phone_number'].'</td>
<td>'.$row['reporting_manager'].'</td>
<td>'.$row['role'].'</td>
<td>'.$row['designation'].'</td>
</tr>';

}

echo '
</table>';

?>

your code looks like it should work. what does a 'view source' in your browser show?

 

if there are empty html-table rows, then it's likely your database table names don't match exactly the $row[...] index names, which would result in php error messages if you have php's error_reporting/display_errors turned full on.

Inside your while loop, you can see what $row contains by doing something like this:

<?php
//...
 
while($row = mysql_fetch_array($result)) {
     echo '<pre>' . print_r($row, true) . '</pre>';
 
     //...
}
 
//...
?>

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.