Displaying Results In A Table?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nishmgopal
Forum Contributor
Posts: 101
Joined: Tue Mar 03, 2009 9:38 am

Displaying Results In A Table?

Post by nishmgopal »

Hello, I have the code below, and wanted to know how I can display the information in a table format?

Code: Select all

$sql = "SELECT * FROM ID_Table WHERE Job_ID IN (SELECT Job_ID FROM Job_ID WHERE Job_ID ='1')";
$result = mysql_query($sql);
 
for($i = 0; $array[$i] = mysql_fetch_assoc($result); $i++);
 
print_r($array);
 
elpepefontana
Forum Newbie
Posts: 5
Joined: Thu Mar 12, 2009 6:34 am

Re: Displaying Results In A Table?

Post by elpepefontana »

I think the following code can help you, check it out.
$sql = "SELECT * FROM ID_Table WHERE Job_ID IN (SELECT Job_ID FROM Job_ID WHERE Job_ID ='1')";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);//counts the total results of the query
$num_fields = mysql_num_fields($result);//table's columns count
print "<table>";
print "<tr>";
for ($a=0;$a<$num_fields;$a++)
{
print "<td>" . mysql_field_name($result,$a) . "</td>";//print column name
}
print "</tr>";
for ($b=0;$b<$num_rows;$b++)
{
$data = mysql_fetch_array($result);
print "<tr>";
for ($c=0;$c<$num_fields;$c++)
{
print "<td>" . $data[$b][mysql_field_name($result,$c) ] . "</td>";
}
print "</tr>";
}
print "</table>";
Post Reply