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 6 of 6
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts

    adding desc to order by causes 0 rows found

    This query
    Code:
    select * from messages   where `to` = 106  order by `when`
    has 60 results
    Code:
    select * from messages   where `to` = 106  order by `when`  desc
    has 0 results

    Code:
    select * from messages   where `to` = 115  order by `when` desc
    has 25 results

    How? Why? and how do I fix it?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,151
    Thanks
    80
    Thanked 4,557 Times in 4,521 Posts
    Time to investigate the actual data.

    SELECT `to`, `when` FROM messages WHERE `to` = 106 ORDER BY `when`

    What does that show you??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Are you absolutely certain that you have escaped those very poorly chosen field names correctly in the original code?

    A good starting point might be to change the field names so that they are not reserved words so you can get rid of the backtick escaping completely.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Those are the exact queries including escapes. The results come back when sorted ascending but not when sorted descending, It was working fine, then a new entry was added and it stopped working, then another new entry (for 106) and it worked fine again. I can see nothing unusual about the data at all.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,129
    Thanks
    2
    Thanked 328 Times in 320 Posts
    How exactly are you running the query and displaying these results?

    The symptom is of the data containing something (html comment, opening html tag) that is causing the result to be hidden when displayed by a browser.

    If a browser is involved in any way with how you are viewing the result, what does the 'view source' of the page in the browser show?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Running the query in HeidiSQL and in php, there are no results found (not just not being displayed). I'm quite flummoxed, I've been doing this for a while and I've never experienced anything like it.


  •  

    Posting Permissions

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