Re: How do I fetch an array of all field names in a mysql database?
- From: Martin Jay <martin@xxxxxxxxxxxxxxxx>
- Date: Fri, 26 May 2006 15:34:55 +0100
In message <PsDdg.3$Jd5.0@xxxxxxxx>, robert <ab@xxxxxxxxxxxxxxxxxxxxxxx> writes
| >$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.
I don't agree with you that it's a good idea to post poor code to help someone "get's (sic) it."
second, how is my code "wrong x 3"?
Well, instead of posting responses to all your rants about what you call my bad programming and methodology I thought I'd roll them into one.
third, where are the "magic numbers"? $i is an index counter and is REQUIRED
by mysql_fetch_field.
Did I say anything about $i?
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.
Perhaps you misunderstood the simple example I posted.
But if you post some of your "doozy [sic] code" here I may tidy it up for you if I have time.
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.
Not all databases have the SHOW keyword or functionality, so what's your point?
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!
I answered the question without berating anyone. The question was:
"...date("m")-1 returns the previous month.
But, if the current month is "01", will this return "12" or "00" ?"
and my answer was:
"'0' would be returned (1 - 1)."
I don't consider this answer to be any less useful than your "you start by RTFM" reply to message <1148469014.190473.71330@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>.
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.
Haven't we just done that? Didn't you read the message your responded to?
until then, m.j., FOAD
That seems to have been your attitude to me for a while now. I don't know why.
--
Martin Jay
Phone/SMS: +44 7740 191877
Fax: +44 870 915 2124
.
- Follow-Ups:
- References:
- How do I fetch an array of all field names in a mysql database?
- From: guttyguppy
- Re: How do I fetch an array of all field names in a mysql database?
- From: guttyguppy
- Re: How do I fetch an array of all field names in a mysql database?
- From: Erlend Klakegg Bergheim
- Re: How do I fetch an array of all field names in a mysql database?
- From: guttyguppy
- Re: How do I fetch an array of all field names in a mysql database?
- From: robert
- Re: How do I fetch an array of all field names in a mysql database?
- From: Martin Jay
- Re: How do I fetch an array of all field names in a mysql database?
- From: robert
- How do I fetch an array of all field names in a mysql database?
- Prev by Date: Re: PDF generation
- Next by Date: Re: "<br>" v "<br\>"
- Previous by thread: Re: How do I fetch an array of all field names in a mysql database?
- Next by thread: Re: How do I fetch an array of all field names in a mysql database?
- Index(es):