On Fri, 03 Sep 2004 03:36:20 GMT, "JV" <jveil.hotpop@com> wrote:
Hi JV..
[color=blue]
>
>"Ian.H" <ian@WINDOZEdigiserv.net> wrote in message
>news:urofj0pauo8c6jj3i00jvdd0bhlmqhcjm5@4ax.com.. .[color=green]
>> Have a look at
>> <http://uk.php.net/manual/en/function.mysql-field-name.php>
>>
>>
>> Should be what you're after =)
>>
>>
>> HTH.[/color][/color]
[color=blue]
>
>thnx ian for timely response[/color]
np =)
[color=blue]
>k looked at it and a couple questions arises ?
>1. is there a variable stored in $result that will tell how may columns are
>in it ?[/color]
<http://uk.php.net/manual/en/function.mysql-num-fields.php>
echo mysql_num_fields($result);
[color=blue]
>and depending on answer from that...
>2. where in loop structure would be best place to put it (obviously at the
>top of loop right after the <table> flag so i can use <th> flags to display
>the headers but it seems like it might interfere with the existing $result
>variable[/color]
-----------------
[! UNTESTED CODE !]
-----------------
$result = mysql_query("
SELECT *
FROM " . TABLE_NAME . "
");
if (is_resource($result)) {
echo "<table>\n<tr>";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo '<th>' . mysql_field_name($result, $i) . '</th>';
}
echo "</tr>\n";
if (mysql_num_rows($result) > 0) {
if ($row = mysql_fetch_assoc($result)) {
do {
echo "<tr>\n";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo '<td>' . $row[mysql_num_fields($result, $i)] . "</td>\n";
}
echo "</tr>\n";
}
while ($row = mysql_fetch_assoc($result));
}
mysql_free_result($result);
}
} else {
die(mysql_error());
}
[color=blue]
>
>thnx again
>JV
>[/color]
HTH (and works) =)
Regards,
Ian
--
Ian.H
digiServ Network
London, UK
http://digiserv.net/