0

I retrieve data from my mySQL server from three columns: ID (an AI data), RANK (an INT value), NAME (TEXT value). I am looking for a way to sort each ROW of data by the RANK in ascending order. I have used the sort() function with arrays, but this only seems to change the RANK around, not the rest of the data. I was also looking at sub-arrays for the data inside arrays, but did not have any success.

I'm not asking for complete code, but I'm struggling to think of a concept to solve this issue. A push in the right direction would be preferable, then I could upload my fixed code.

Thanks for your help in advance.

4
  • 4
    ORDER BY RANK ASC? Feb 27, 2015 at 19:13
  • I didn't even consider editing the data while I was retrieving it 0.o. Thanks, you've saved me a huge headache, Feb 27, 2015 at 19:14
  • Adding order to the query is the best way to go. However, if you ever have an array and PHP and you know exactly how you want to sort it and you simply cannot get sort to work, look at usort. You write your own comparison function and force it to behave as you want it to behave.
    – kainaw
    Feb 27, 2015 at 19:17
  • Because I'm echoing my data in rows, I'm getting a "Notice: Trying to get property of non-object in" ERROR when I try and use my data that has been ordered. Is this a side effect of the ORDER BY, or am I doing it wrong? Also, how would I fix it. (code here: pastebin.com/7HkDgTu9) Feb 27, 2015 at 19:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.