Jump to content

Reversed array


NLCJ

Recommended Posts

Hello,

I've created a little script that fetches all dates from the database and puts it into a select list. The problem is that the today date is at the bottom, so a lot of scrolling to do if you need that date. That's why I need it reversed. I got this:

while($d_dailystatistics = mysql_fetch_array($d_getdailystatistics)) {

And here I'm stuck, I've tried to use array_reverse, with no result. Googling wasn't really helping either and W3Schools is offline for me (I know it's on, just a provider issue).

 

Thanks,

NLCJ

Link to comment
https://forums.phpfreaks.com/topic/215034-reversed-array/
Share on other sites

I'm not sure what issue you're actually having - the data held inside $d_dailtstatistics is an array so you can access any piece of data in any order.

 

You might find it easier if you use mysql_fetch_assoc() instead as you can read the array by name rather than index.

 

For example, if you had the date in your table as "dt" then you would use this to access it:

echo $d_dailystatistics['dt'];

Link to comment
https://forums.phpfreaks.com/topic/215034-reversed-array/#findComment-1118517
Share on other sites

OK I'm not sure if this is a question of your SELECT query needs to be edited or PHP.

 

Let's say this is your query (I'm guessing as you've not given me much to play with)

SELECT dt FROM table WHERE field=condition

 

If you want to reverse the output you'd use this:

SELECT dt FROM table WHERE field=condition ORDER BY dt DESC

Link to comment
https://forums.phpfreaks.com/topic/215034-reversed-array/#findComment-1118523
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.