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
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
Share on other sites

Thanks for your reply, my problem isn't the reading of the array. I will try to explain.

Currently the result is:

2010-10-01
2010-10-02
2010-10-03

I would like it to be like:

2010-10-03
2010-10-02
2010-10-01

 

So the array has to be 'reversed' somehow.

Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.