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!