Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post

    AH! HELP! Select * from error

    WHY wont this work?

    Instead of displaying the zipcode, city, & state

    and stuff, it says Array() :S

    Code:
    <?
    $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:

    Code:
    local
    zip_code
    state_abreviation
    latitude
    longitude
    city
    state
    thanks!

    ~Shadow~

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Hmm. Could be because mysql_fetch_array() returns an array?

    PHP Language Reference

  • #3
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    I learn by example dude.

    Not reference.

    Thas just not the way I roll..

  • #4
    New Coder
    Join Date
    Mar 2009
    Location
    Michigan
    Posts
    26
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,602
    Thanks
    78
    Thanked 4,387 Times in 4,352 Posts
    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??

  • #6
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    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~

  • #7
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    Quote Originally Posted by ShadowIce View Post
    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
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #8
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by ShadowIce View Post
    *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.
    Quote Originally Posted by ShadowIce View Post
    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.
    Last edited by bdl; 05-01-2009 at 07:33 PM.

  • #9
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    In ShadowIce's defense, bdl's first answer was very condescending.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,602
    Thanks
    78
    Thanked 4,387 Times in 4,352 Posts
    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.

  • #11
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by Fumigator View Post
    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 .

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,602
    Thanks
    78
    Thanked 4,387 Times in 4,352 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •