TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

Date block sorting......

Page: 1 Reply
Mar 20th 2004#145812 Report
Member since: Dec 9th 2003
Posts: 180
I'm working on my archive.php. Anyone happen to know an easy way to list those entries by month and year ?
kinda like this:

Month W Year Y
blog entry 1
blog entry 2
blog entry 3

Month X Year Y
blog entry 1
blog entry 2
blog entry 3


(it's a MySQL DB and the dates are in UNIX TIMESTAMP format)

etc...etc....i don't think i'll be finishing this one by the end of the weekend....:-/
Reply with Quote Reply
Mar 20th 2004#145814 Report
Member since: Nov 26th 2001
Posts: 2586
It is really quite easy. Look on php.net under functions for [php]date()[/php]

It takes 1 set of arguments that are mandatory and an optional UNIX TIMESTAMP =) So it converts it for you.

For example:

[php]
$timestamp = // where you get your mySQL time stamp.
$my_date = date('r', $timestamp);
[/php]
This would make it: Thu, 21 Dec 2000 16:01:07 +0200 , format (the 'r' flag)

Note if you are using the mySQL built in timestamp you might need to convert it to a Unix timestamp via the php function strtotime();
Reply with Quote Reply
Mar 20th 2004#145815 Report
Member since: Nov 26th 2001
Posts: 2586
Oh and all you need to do is query them and use something like "SELECT * FROM your_archive_table ORDER BY timestamp DESC" -> That would get them in the proper order. Then use a php mysql function that grabs them into an array, loop thru the array and list each one - while converting the date and it will be a breeze. I can help you later if you need.
Reply with Quote Reply
Mar 20th 2004#145818 Report
Member since: Dec 9th 2003
Posts: 180
[QUOTE=Marble]Oh and all you need to do is query them and use something like "SELECT * FROM your_archive_table ORDER BY timestamp DESC" -> That would get them in the proper order. Then use a php mysql function that grabs them into an array, loop thru the array and list each one - while converting the date and it will be a breeze. I can help you later if you need.[/QUOTE]

I know SQL but i'm still learning php so i wouldn't know where to start when it comes to writing a loop that does that kind of filtering. Help would be much appreciated.


i'm reading the php manual on date()...there's much more info there then i expected..

*thinks to self:"RTFM!"*
Reply with Quote Reply
Mar 20th 2004#145853 Report
Member since: Nov 26th 2001
Posts: 2586
php.net is the best source of php code. Lots of examples as well.

after you make your query, use mysql_fetch_array or mysql_fetch_assoc -> the former returns indiced and associative arrays, and the latter just associative. I use mostly associative arrays because when you return 20-30 items into an array it's easier to view array['some_name'] rather than array['23'].

In these instances I use while loops quite a bit. For example,
[php]

$result = mysql_query($sql);
while ( $archive = mysql_fetch_assoc($result)) {
print "

".$archive['some_db_column']."

";
}
[/php]

So for each result in your query it will put that between some html paragraphs. I have a mysql php class I put together that I use all the time, if you want email me [email]john@pixelday.com[/email] and I can attach it to you.
Reply with Quote Reply


[/php]

Where it shows those, just use a different set of flags....
Mar 20th 2004#145855 Report
Member since: Nov 26th 2001
Posts: 2586
[php]
Reply with Quote Reply


[/php]

Where it shows those, just use a different set of flags....[/QUOTE]

what i'm trying to do is get visual sets of posts for each month.
....for some reason $pmonth only gets changed once...
Mar 21st 2004#145867 Report
Member since: Dec 9th 2003
Posts: 180
[QUOTE=Marble][php]
Reply with Quote Reply
Mar 21st 2004#145875 Report
Member since: Dec 9th 2003
Posts: 180
solved it ! I just changed the loop I'd already written =)

Thanks for the tips anyhow.....


[php]
Archive
$sql = "select *, UNIX_TIMESTAMP(Sent) AS date from mblog_Blog order by ID DESC";
$r = $mpage->DoQuery($sql, 1);
$pmonth="";
foreach ($r as $s) {
echo("");
?>
$tmonth = date("n",$s[date]);
if ($pmonth==$tmonth) echo(""); else
{$pmonth=$tmonth;
?>



Admin){ ?>





if ($mpage->Admin){
?>





Admin){ ?>
TitleDateTime
55){ echo(substr($s[Title],0,55).'...');} else { echo($s[Title]);}; ?> Edit Del
 

[/php]
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum