|
Posted by robert on 09/28/34 11:48
<guttyguppy@gmail.com> wrote in message
news:1148586513.290292.272550@j73g2000cwa.googlegroups.com...
| Thanks for the lead-the manual is so huge and tough to read that I gave
| up the first time, but now I think I've got it:
|
| $query="SELECT * FROM my_table";
| $result=mysql_query($query);
| $i = 0;
| while ($i < mysql_num_fields($result)) {
| $meta = mysql_fetch_field($result, $i);
| echo $meta->name."</br>\n";
| $i++;
| }
|
| Is that good, non-depracated code though?
while it will work, it is certainly not as efficient as it could be. you
should never eval with a function if the return value isn't expected to
change...meaning, only do it when you absolutely have to. notice the added
where clause...since you only want field names and don't need any data
(based on your example).
$sql = "SELECT * FROM my_table WHERE 1 = 2";
$records = mysql_query($sql);
$numFields = mysql_num_fields($records);
for ($i = 0; $i < $numFields; $i++)
{
$field = mysql_fetch_field($records, $i);
echo $field->name . "<br />\r\n";
}
Navigation:
[Reply to this message]
|