Aftermath Posted June 29, 2006 Share Posted June 29, 2006 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] <?phpmysql_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] Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/ Share on other sites More sharing options...
thepip3r Posted June 29, 2006 Share Posted June 29, 2006 easy, convert your dates to Unix timestamp format using strtotime(), load all of your relative data into a temp assoc. array and then sort the array based on the timestamp element. Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/#findComment-50998 Share on other sites More sharing options...
Aftermath Posted June 29, 2006 Author Share Posted June 29, 2006 ok. I think I will be able to figure it out. thanks ^_^ Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/#findComment-51003 Share on other sites More sharing options...
thepip3r Posted June 29, 2006 Share Posted June 29, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/#findComment-51004 Share on other sites More sharing options...
Aftermath Posted June 29, 2006 Author Share Posted June 29, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/#findComment-51030 Share on other sites More sharing options...
thepip3r Posted June 29, 2006 Share Posted June 29, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/#findComment-51045 Share on other sites More sharing options...
Aftermath Posted June 30, 2006 Author Share Posted June 30, 2006 I don't suppose you can post that link again. It seems it is gone and I neglected to bookmark it last nite. Quote Link to comment https://forums.phpfreaks.com/topic/13247-organizing-data-from-database/#findComment-51371 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.