|
Posted by robert on 05/26/06 16:34
| >$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";
|
first, my example is in keeping with the op's methodology...so that he
"get's it" through comparison.
second, how is my code "wrong x 3"?
third, where are the "magic numbers"? $i is an index counter and is REQUIRED
by mysql_fetch_field.
forth, your "IMO" solution is exactly "IMO". even still, you should
formalize your writing so that the "while" has loop body brakets. any arg
you make against that will be met with some doozy code i'd like you to
interpret that uses your style...like quadruple, single line nested
for/foreach's amongst multinested if's.
fifth, not all db's HAVE a "DESCRIBE" keyword or functionality...i write
from experience so that when i say "select * from table where 1 = 2", i know
it will return results - mysql or not.
sixth, i post code that answers questions instead of berating people with
things like this response: "1 - 1 = 0 :^)"...then again, you are (as noted
before and maintained now) as useful as a wort...just not as smart!
now, if you'd like to show me some examples of my "bloated" code, go
ahead...i'm festidious when it comes to maintenance and brevity of code, so
i'll be waiting. it would also be in your favor to post *your* own code that
shows the reduction of bloat and accomplishes the same task as the code you
are berating.
until then, m.j., FOAD
Navigation:
[Reply to this message]
|