dhcrusoe Posted January 7, 2009 Share Posted January 7, 2009 Hey all, For some reason, this query keeps pulling up the oldest data (with the lowest counts)... instead of the most recent entries (with the highest counts)... any insights?? thanks! $top10 = mysql_query("SELECT votes,date,progname FROM data where prog<>19 ORDER BY date,votes DESC LIMIT 10") or trigger_error("MySQL Error", E_USER_WARNING ); $citizenschool = mysql_query("SELECT votes,date,progname FROM data where prog=19 ORDER BY date,votes DESC LIMIT 1") or trigger_error("MySQL Error", E_USER_WARNING ); Basically, it needs to: A) Pull up the top 10 newest items with the highest vote count B) Pull up the newest entry for citizenschool so I can report its vote count All of this is displayed here: http://citizenschools.org/change/monitor.html but is reporting old data for some reason I don't understand :/ Thanks! --Dave Link to comment https://forums.phpfreaks.com/topic/139878-yet-another-query-issue-wrong-data-coming-up/ Share on other sites More sharing options...
Clinton Posted January 7, 2009 Share Posted January 7, 2009 Did you try ASC instead of DESC? Link to comment https://forums.phpfreaks.com/topic/139878-yet-another-query-issue-wrong-data-coming-up/#findComment-731804 Share on other sites More sharing options...
dhcrusoe Posted January 7, 2009 Author Share Posted January 7, 2009 Did you try ASC instead of DESC? Nod -- same result for some reason?? Link to comment https://forums.phpfreaks.com/topic/139878-yet-another-query-issue-wrong-data-coming-up/#findComment-731822 Share on other sites More sharing options...
Clinton Posted January 7, 2009 Share Posted January 7, 2009 "That's it, I'm out of ideas. We're closed. Hot air balloon? Too expensive. Giant slingshot? Too conspicuous. Enormous wooden horse? Too Greek!" I know it's got to be something in that realm but I don't have the expertise like the rest of these guys. Sorry it didn't work. Link to comment https://forums.phpfreaks.com/topic/139878-yet-another-query-issue-wrong-data-coming-up/#findComment-731825 Share on other sites More sharing options...
DarkSuperHero Posted January 7, 2009 Share Posted January 7, 2009 im not too comfortable with SQL queries...i know just enough to get by...but what does "prog<>19 " in your code mean ? Link to comment https://forums.phpfreaks.com/topic/139878-yet-another-query-issue-wrong-data-coming-up/#findComment-731832 Share on other sites More sharing options...
l_kris06 Posted January 7, 2009 Share Posted January 7, 2009 <> = lesser than or greater than but not equal to. why are you trying to do "order by" on two columns? your final output is constrained with date. Meaning, you want the entire output of your query to be sorted with latest one on top. $top10 = mysql_query("SELECT votes,date,progname FROM data where prog<>19 ORDER BY date DESC LIMIT 10") or trigger_error("MySQL Error", E_USER_WARNING ); $citizenschool = mysql_query("SELECT votes,date,progname FROM data where prog=19 ORDER BY date DESC LIMIT 1") or trigger_error("MySQL Error", E_USER_WARNING ); The above code will work just fine. Link to comment https://forums.phpfreaks.com/topic/139878-yet-another-query-issue-wrong-data-coming-up/#findComment-731873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.