Page 1 of 1

Displaying Results In A Table?

Posted: Thu Mar 12, 2009 2:50 pm
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);
 

Re: Displaying Results In A Table?

Posted: Fri Mar 13, 2009 9:13 am
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>";