Home ORDER by ASC/DESC not working. Just ORDER BY RAND() when using AJAX/PHP
Reply: 0

ORDER by ASC/DESC not working. Just ORDER BY RAND() when using AJAX/PHP

Ed91gg
1#
Ed91gg Published in 2017-12-07 23:46:11Z

I haven't found anything related to this question so I decided to post it.

The thing is as the title says, when I click a button, I make an jquery ajax call to test.php and I get a name returned in a div, and each time I click the button again I get a different name from my DB, ONLY if my SQL says ORDER BY RAND();

If I change it to ORDER BY column_name ASC; then, click the button, make the ajax call and return the result as JSON, it only shows the first name of the column. And somehow it makes sense.

This will work every time I click the button and show:

SELECT * FROM table WHERE names = '(whatever parameter I pass)' ORDER BY RAND(); 

This will ONLY show the first name in the table no matter how much I click the button:

SELECT * FROM table WHERE names = '(whatever parameter I pass)' ORDER BY names ASC"; 

(so I will only get let's say, ANDY).

Same for DESC, and I will only get let's say "Zamora".

I'm sure a lot of people have struggled with this. Cheers!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.293684 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO