Re: results of query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> What does everyone typically use to display the results of a query.  For
> example, I have a database that has a series of subjects and grades.  If I
> select * from the table, I want a nice way for the data to be displayed.
In
> cold fusion, I can simply use a grid that dynamically fills in.  Can I do
> this with php?

There is no "automatic" way to do it with PHP. You have to write the code to
display it yourself and this depends on how you want to display it. If you
just want to display it in a table, then you can write a generic function to
display column names and values in a table given a result set.

Assuming $result is a result set from any query.

echo "<table>";
while($row = mysql_fetch_row($result))
{
  echo "<tr><td>" . implode("</td><td>",$row) . "</td></tr>\n";
}
echo "</table>";

Adapt to your needs to add error checking, empty fields, header row, etc.
You can use the mysql_field_name() functions to get the field names from the
result set to create your header row, so you don't actually have to know the
names from the query.

---John Holmes...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux