...

View Full Version : AH! HELP! Select * from error



ShadowIce
05-01-2009, 01:04 AM
WHY wont this work?

Instead of displaying the zipcode, city, & state

and stuff, it says Array() :S


<?
$zmydb = mysql_connect("localhost", "root", "Pass") or die(mysql_error());
$mydb=mysql_select_db("weather") or die(mysql_error());
$blah = mysql_query("SELECT * FROM location WHERE city = zip_code") or die(mysql_error());
$info = mysql_fetch_array( $blah ) or die(mysql_error());
?>
<?echo "<select style=\"font-weight:bold;margin:0 0 0 0;padding:0 0 0 0;\" name=\"here\" id=\"here\"><option value=".$info.">".$info."</option></select>";?>

table name is location

column names:


local
zip_code
state_abreviation
latitude
longitude
city
state

thanks!

~Shadow~

bdl
05-01-2009, 01:40 AM
Hmm. Could be because mysql_fetch_array() (http://www.php.net/mysql_fetch_array) returns an array?

PHP Language Reference (http://www.php.net/langref)

ShadowIce
05-01-2009, 01:50 AM
I learn by example dude.

Not reference.

Thas just not the way I roll..

Shinykirby
05-01-2009, 04:22 AM
If you looked through the page for 5 seconds, you would see an Array section which does have examples.

http://us2.php.net/manual/en/language.types.array.php

Old Pedant
05-01-2009, 08:37 AM
But even so, if you look at his code, it doesn't make sense.

The query is weird, to begin with: How many database tables would you find where indeed the value of the city field is the same as the value of the zip_code field?? Or maybe he is trying to find the records in that table that are bogus???

But even so, why would you display all such records in a <SELECT>???

And his <OPTION>s will never work if indeed any of those fields have a space in them.

And in any case, since he has no loop in there, he's only going to get *ONE* record, even if the query returns thousands.

And and and....

Just seems to me that maybe, indeed, he needs an example. But a fully function example, because what he has is so far off from usable.

No??

ShadowIce
05-01-2009, 01:08 PM
O i dont know.. Maybe because I wanna display the city, and state and zipcode for a WEATHER SCRIPT? ><

*sigh* Why do I even bother coming on these forums is if alls u ppl do is criticize. Forums are to HELP ppl. not to criticize. So excuse me for sounding rude, but Im tellin u like it is.

Now if u excuse me, I think Ill take my question else where until I get some answers.. :(

~Shadow~

bazz
05-01-2009, 02:49 PM
O i dont know.. Maybe because I wanna display the city, and state and zipcode for a WEATHER SCRIPT? ><


Then why would you expect a city to = a zip code? look at your query again in more depth and look for errors instead of reaching for help as soon as it doesn't work. I have been guilty of that in the past ~ due to frustration ~ but I am sure it is not the best way to go.

You should select only the fields you want data from by naming them in your query. select col1 col2 col3 from table bleh...



*sigh* Why do I even bother coming on these forums is if alls u ppl do is criticize. Forums are to HELP ppl. not to criticize. So excuse me for sounding rude, but Im tellin u like it is.


Actually this forum is for helping people who are actively trying to learn. I do not see any criticism being aimed at you above. But if you want to take offence, no-one can stop you. I find it hilarious that you see the posts as being critical of you , you then complain about it and then do the same thing in retaliation. You have just negated any point you had in complaining.

Sadly, in doing so, you say more about yourself ~ in a negative way ~ than the writers ever could. y'see, they have made some points about the code posted - valid points (imv). Taking offence shows several things:

1. you are unwilling to learn
2. instead of questioning what they wrote, you lambast them - showing immaturity
3. Because of points 1. and 2., you make any further contribution by them a waste of their FREE time.

bazz

bdl
05-01-2009, 07:30 PM
*sigh* Why do I even bother coming on these forums is if alls u ppl do is criticize. Forums are to HELP ppl. not to criticize. So excuse me for sounding rude, but Im tellin u like it is.

Take it as constructive criticism. I think most forum regulars like myself or Old Pedant have been around the block a time or two and are just trying to point things out that will eventually bite you in the arse. Or things that are common coding mistakes that could be done more efficiently. Sometimes, as in my post above, for example, a tongue-in-cheek reply can be misconstrued as being rude. I assure you, it was not meant to be.


Now if u excuse me, I think Ill take my question else where until I get some answers.. :(
Now, this is the real crux of the matter that you have taken some heat over. I was the first to respond, and pointed out to you that you're receiving an array in the $info assignment. The links I provided were more than adequate to get you going, with examples. I often just link the PHP manual because it's more likely there are better examples available than we can come up with, and why rewrite good content?

So if you choose not to learn, that's fine. But playing the blame game ain't gonna fly. That's how we roll.
Note I didn't mention this should be in the PHP forum, anyway. :p

Fumigator
05-01-2009, 09:56 PM
In ShadowIce's defense, bdl's first answer was very condescending.

Old Pedant
05-02-2009, 01:28 AM
Perhaps so, but then ShadowIce's answer was...well, to me at least, irritating.

If a person won't read documentation, then why is he/she writing code? Ultimately, the ONLY correct source of answers has to be documentation (yes, yes, I know...occasionally even the docs are wrong...but not very often). If you rely on other people to give you examples, you (a) may miss a better way because it wasn't covered in the example, (b) may get a completely wrong answer because the example either missed something or you misunderstood how to apply it to your case, and (c) don't really expand your knowledge much (you'll just have to come back and ask for another example next time).

If ShadowIce's code had at least been *close* to right--if he'd had the right idea with a couple of details wrong--then BDL's answer may have been harsh. But the code is so very very far from making sense--let alone working--that it *feels* like another case of a student wanting us to do his/her homework. [And if that's not the case, I'll apologize. But it sure looks like student code.]

Heck, I really *AM* curious whether the use of "...WHERE city = zip_code..." was intentional--and correct--or not.

bdl
05-02-2009, 02:39 AM
In ShadowIce's defense, bdl's first answer was very condescending.

I disagree. If you read my followup post, you'd see it was not meant to be. I do tend to have a very dry sense of humor (and I can be sarcastic) but that comment was not meant to be condescending. Maybe I should have added a :) or ;).

Old Pedant
05-02-2009, 04:19 AM
I'm not sure how a response of RTFM can ever be "condescending." Especially when it is crystal clear that the requestor has clearly not even peeked at the FM. For my own part, I always try to ensure I've not only R'ed the FM but also that I've read any docs the FM links to and and and... Only when I feel really stuck do I then ask for help.

Besides, it's (a) much more satisfying to figure out the answer yourself and (b) you'll retain what you have learned much better.

If any answer was condescending, in this thread, mine was. But it, too, wasn't meant to be. It was only meant to say that ShadowIce has many many more problems than just not realizing he is getting back an array. And that if he wants an example, the best thing to do would be to find some sample PHP code (and SQL code!) that does nearly the same thing he *wants* to do, as a starting point.

Anyway, if ShadowIce were to return and explain--in English, not in code--what he is after, then I think if nothing else we could show him dozens if not hundreds of online examples that at least parallel his needs.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum