Results 1 to 7 of 7

Thread: Using more then one AND after WHERE

  1. #1
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default Using more then one AND after WHERE

    I'm assuming this is something simple but cant find any information about it. I need to basically get something from the database where it equals 3 or more parameters

    so for example:

    SELECT car FROM cars WHERE type='whatever' AND maker='whatever' AND model='whatever'

    I had my select set up the same way but with my real info and was trying to use more then one AND till I realized that a query like that errors out.

    so I tried this:

    SELECT car FROM cars WHERE type='whatever', maker='whatever', model='whatever'

    this errors out as well
    so how exactly do I go about telling it to select some where its equal to these 3 things?

    any help would be appreciated

  2. #2
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default hum

    SELECT `car` FROM `cars` WHERE `type`='whatever' AND `maker`='whatever' AND `model`='whatever'

    that code should work,
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  3. #3
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    that doesn't work, that is exactly what I am using and it errors out. I went back and put one in at a time and as soon as I go past one AND it errors out. Thats why I am looking for for a different solution.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Then you're doing something wrong — that code is perfectly valid, at least in MySQL, with or without the backticks.

    Please provide actual information, like which database you're using, how you're accessing it, what the error is, &c. If you say '$valid_code causes an error when I use it!' my first instinct is to reply, 'Good for you. What am I supposed to do about it?' Some people seem to think that people in help forums have some sort of Magick Ritual of Error-Fixing. 'Oh, OK, I've sacrificed a chicken to the gods of databases, you shouldn't get it any more! Have a nice day!'

    Additionally, this is not a PHP question — moving to the database forum.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    I don't assume that people in help forums have some magic solving problems.

    As someone that tries to answers as many questions as I can as well when I'm on a forum I also know that people just putting down a whole bunch of code when its not really needed doesnt usually get them the help they need or if someone does fix it teach them anything.

    I went back through my string and put the ANDs in one at a time and checked if it would error. I was wrong with what I said last night it was after I went past two ANDs that it would error. As soon as I put the third AND in is when it would error out. So I figured maybe there is a limit to how many ANDs you could use and if there was another way of going about it. I couldnt find any information on it from google or on the mysql site so I came here to ask...

    id I wasnt looking to actual learn something I would have just thrown my code up here and say please fix I have an error. After reading ya'lls replies I decided to go back and check everything again. I didnt change anything but I re-uploaded and tested and it seems to be working fine now. I dont know why maybe my server was just bugging out.

    thanks for looking I appreciate it. I ask to learn not for some one else to solve my problems.
    Last edited by punstc; 02-14-2009 at 05:19 PM.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    As someone that tries to answers as many questions as I can as well when I'm on a forum I also know that people just putting down a whole bunch of code when its not really needed doesnt usually get them the help they need or if someone does fix it teach them anything.
    Certainly, reading through pages and pages of code to get to the relevant bit is annoying, but having to post a reply saying 'need more info' and then wait is moreso. Too much code is better than too little code, but as a bare minimum the actual error encountered and (in this case) the database software on which it occurred should be given. Even now I've no idea if you were talking about MySQL, PostgreSQL, SQLite, Microsoft SQL Server, or perhaps something entirely different. They all have considerably different languages, and 'the database' doesn't tell me anything. You could have been talking about a text file with some home-brewed semi-SQL for all I know.

    Anyway, don't mind me. I'm just crotchety.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2007
    Location
    Harrisburg, PA
    Posts
    131
    Thanks
    6
    Thanked 9 Times in 9 Posts

    Default

    yeah your right I should have at least given the error. It was just telling my my string was wrong for mysql_fetch_assoc I'm still pretty new to php so I've made plenty of mistakes before where I knew what it was telling me was wrong.

    Like I said I was really looking for more information then really some one to fix the error.

    And thank you for taking the time to even look I really do appreciate it

Bookmarks

Posting Permissions

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