Re: Extracting result - unknown number of fields

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

 



Dillon, John wrote:

OK, please ignore, I believe I've found the answer in the manual notes:

$query="your SQL";
$result=mysql_query($query) or die("Query ($query) sucks!");
$fields=mysql_num_fields($result);

echo "<table>\n<tr>";
for ($i=0; $i < mysql_num_fields($result); $i++) //Table Header

Calculate the value for mysql_num_fields() outside of your for() loop to improve effeciency.


$num_fields = mysql_num_fields($result);
for($i=0; $i < $num_fields; $i++) // Table Header

{ print "<th>".mysql_field_name($result, $i)."</th>"; }
echo "</tr>\n";
while ($row = mysql_fetch_row($result)) { //Table body
echo "<tr>";
for ($f=0; $f < $fields; $f++) {
echo "<td>$row[$f]</td>"; }
echo "</tr>\n";}
echo "</table>
http://www.php.net/manual/en/function.mysql-num-fields.php

-- ---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

PHP|Architect: A magazine for PHP Professionals – www.phparch.com





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