You are here: Re: How do I fetch an array of all field names in a mysql database? « All PHP « IT news, forums, messages
Re: How do I fetch an array of all field names in a mysql database?

Posted by Martin Jay on 05/26/06 13:55

In message <X8odg.2002$m61.581@fe05.lga>, robert
<ab@no.spam-alama-ding-dong> writes

>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

>$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";
>}

You should be ashamed of yourself, Robert. That is wrong, wrong, wrong.
It relies on "magic numbers," which you've previously described as
"NONSENSE, "STUPID programming," and "amature." [Sic]

Like many examples you post here, your code is bloated, overly
complicated, and poor.

IMO a much neater solution would be:

$result=mysql_query("DESCRIBE $mysql_table");
while ($row = mysql_fetch_array($result))
echo $row['Field']."<br>\r\n";

--
Martin Jay

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация