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
    New Coder
    Join Date
    Sep 2011
    Location
    127.0.0.1
    Posts
    67
    Thanks
    19
    Thanked 0 Times in 0 Posts

    How to select data from MySQL database with two 'Where' conditions?

    PHP Code:
    mysql_query("SELECT * FROM users WHERE type='IZ' AND user_type='fo' AND reg_time='".$time."' ORDER BY `full_name`"); 
    why this is not working?

  • #2
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Code:
    mysql_query("SELECT * FROM users WHERE type='IZ' AND user_type='fo' AND reg_time='".$time."' ORDER BY full_name");
    You do not need quotes around ORDER BY

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by melloorr View Post
    Code:
    mysql_query("SELECT * FROM users WHERE type='IZ' AND user_type='fo' AND reg_time='".$time."' ORDER BY full_name");
    You do not need quotes around ORDER BY


    Supposing you have a column called order for a list of items you want displayed in a certain order. Try using "order by order asc" and you'll get an sql error.

    BACK TICKS (not quotes) whilst not always necessary should not be discouraged.

    @sonic: Have you tried printing the query to be sure that the time value is correct? - Have you also tried running the query manually via phpmyadmin? - if there is a fault with the query then that will tell you. Alternatively you should use the mysql_error() function and print the error it returns.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    I have just tried to put back ticks in my query, and it wouldn't order them
    Last edited by melloorr; 01-07-2012 at 07:18 PM.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    It will if you're doing it right. There are some situations where it doesn't work such as in joins where you're naming tables along with columns.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Quote Originally Posted by tangoforce View Post
    It will if you're doing it right. There are some situations where it doesn't work such as in joins where you're naming tables along with columns.
    I used
    PHP Code:
    $query mysql_query("SELECT * FROM users ORDER BY 'username' DESC")or die(mysql_error()); 

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Those are not backticks. They are just single quotes.

    Backtick: `
    Single quote: '

    Button usually under the esc key is a backtick
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    melloorr (01-07-2012)

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by tangoforce View Post
    BACK TICKS (not quotes)


    Again mellor, while you're trying to help you're giving out wrongful advice based on your inexperience with PHP. While its admirable that you are trying to help people you're still poking at shadows and you don't yet realise when you're out of your depth.

    BACK TICKS are not quotes. You have quite clearly not taken the slightest bit of notice of my previous reply explaining this and you've not noticed the difference in the SQL in sonics opening post.

    This is a quote: '
    This is a back tick: `

    If you can't see the difference then you need to do one of several things:
    • Change your screen resolution to something you can read
    • Use windows magnifier in the start>accessories folder
    • Put a magnifying glass against the screen


    On my UK-Layout keyboard the backtick is the key to the left of number 1/! just above the tab key.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    Thanks _Aerospace_Eng_

    And sorry again tangoforce. While I admit I was wrong, I didn't actually say don't use back ticks, so 'wrongful advice' is a bit harsh. And you are right, my screen is 720p and my resolution is 1080p so it is quite difficult seeing the difference.
    To be honest, I was thinking about getting an apprenticeship in PHP (funny, I know) but I doubt I will get hired with the stupid/silly mistakes I make.

    Sorry, again, and you will probably be seeing less of me.

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by melloorr View Post
    While I admit I was wrong, I didn't actually say don't use back ticks, so 'wrongful advice' is a bit harsh
    No, wrongful advice is correct. You advised the op to remove the quotes thinking that they were quotes and even giving a sample showing the back ticks being removed. That was wrongful advice and saying it wasn't over a technicality like the name of the marks when you've just supplied SQL showing exactly what you mean is not going to do you any favours.

    Quote Originally Posted by melloorr View Post
    Sorry, again, and you will probably be seeing less of me.
    No need to try and put me on a guilt trip, I gave you advice last week about posting with little experience. This forum is a good forum for anyone interested in PHP and I'd hate to see you decide to leave just because someone has pointed out your errors because thats how you learn and become better at it. You clearly have something about you as a php programmer because I've seen some of your other replies showing people how to do some debugging. A lot of php newbies can't even work out how to do things like that so you have the potential to be a very good PHP programmer. Just don't try to take on too much and advise on things that you've not yet mastered thats all I'm trying to say.

    As for the apprenticeship, if you can get such a thing then GO FOR IT. Thats what they're there for - to help you learn and earn a few quid.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    Regular Coder
    Join Date
    Dec 2011
    Location
    NW England
    Posts
    194
    Thanks
    8
    Thanked 15 Times in 15 Posts
    I'm not trying to make you feel guilty, I'm just letting you know that I will not be posting as much because, as you say, I have not learned enough. So I will learn more.

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,341
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Fair enough but remember to come back here and if you can get that php apprenticeship then go for it.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

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