Jump to content

Organizing Data From Database


Aftermath

Recommended Posts

Hello all. What i'm trying to do here is make it so that when it reads the info from the database it will orgranize it date.

EX:

June 28 2006
*Whatever title*
*Second title if there is one*
June 27 2006
*Another title*

Below is my code of what i have so far... Any help would be much appreciated.

[code]    <?php
mysql_connect ('localhost', ' ', ' ');
mysql_select_db (' ');

$result = mysql_query("SELECT * FROM post_table ORDER BY id DESC LIMIT 10");

while ($row = mysql_fetch_array($result)) {
       $id = $row['id'];
        $title = $row['title'];
        $user = $row['username'];
    $date = date("d/n/y", $row['timestamp']);
                      
        echo "<a href='entries.php?id=$id'>($date) $title - $user</a><br />";
}

                ?> [/code]
Link to comment
Share on other sites

good that's what we like, people who are willing to try to do it themselves instead of asking for code handed to them. if you can't figure it out or have problems along the way, please feel free to ask and we can elaborate on the process but as long as you understand the logic and the ways to get there, you should be able to fight your way through it. again, please feel free to post again for further troubles. =D
Link to comment
Share on other sites

I can't for the life of my figure out how to put it into an array. I have gone to the php.net site and read through several pages of about array's and read the strtotime page. I understand the logic i need to make this page, but I just don't have the expereince or knowledge to do it.
Does anyone have a link to a tutorial or something similar to this?
Link to comment
Share on other sites

[code]$tempArray = array();
while ($row = mysql_fetch_assoc($result)) {
  # Here we write all of your associated row values to a multidimensional array with the timestamp being the parent element in it's own dimension so we can run a sort based off of the integer value of the unix timestamp represented by converting your date to secs.
  foreach ($row as $key => $val) {
    $timestamp = strtotime($row['timestamp']);
    $tempArray[$timestamp]][$row[$key]] = $val;
  }

}[/code]

now that i've showed you how to convert your data into a unix timestamp and add your data into the multi-dimensional array, now just figure out how to sort that array based off of the 1st dimension element.
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.