Jump to content

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>';

?>
Edited by mac_gyver
code tags please

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>';
 
     //...
}
 
//...
?>
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.