Page 1 of 1

Blog archiving question

Posted: Tue Feb 21, 2006 3:46 am
by m0nk3yb0y
I'm building my blog as a learning project. I have all the basic functionality working fine where I have become stuck is in creating an archiving script. I have been going in circles trying to plan a script to display my archive.
They I invision it displaying is like this:-

Year
month1
week1
week2
week3
week4
month2
week1
week2
...

The weeks would be urls that pass start/end date variables to the archive script which then prints posts between the relevant dates. I think I have the theory correct. I'm just not sure how to implement this other than hardcoding the html with the date variables myself.

heres my db structure:

-- Table structure for table `news`
--

CREATE TABLE `news` (
`idnews` int(11) NOT NULL auto_increment,
`title` varchar(255) default NULL,
`text` text NOT NULL,
`iduser` int(11) default NULL,
`postdate` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`idnews`)
) TYPE=MyISAM AUTO_INCREMENT=42 ;

Any help would be greatly appreciated

Posted: Tue Feb 21, 2006 9:09 am
by feyd
What particular part do you need a nudge in? The SQL? The output into HTML?

Posted: Tue Feb 21, 2006 10:10 am
by s.dot
I'm just not sure how to implement this other than hardcoding the html with the date variables myself.
I'm not sure what you mean by this. If the date variable is passed through the url then you should have no problem accessing it.

Code: Select all

<?php
if(!empty($_GET['date_var'])){
   // some html formatting maybe?
   echo "<p>{$_GET['date_var']}</p>";
}

Posted: Tue Feb 21, 2006 10:37 am
by m0nk3yb0y
Ok, Sorry to confuse you guys. I'm new here and trying to explain as best I can.

I need some help unfortunately with the direction of the script. In other words I like to know how you guys would go about writing a script which queries the database and spits out a bunch of links to groups of posts.

Did that make any sense?

Do I need to do this in a bunch of nested if statements and loops?

Posted: Tue Feb 21, 2006 10:43 am
by s.dot
I would using $_GET variables as you suggested.

IE: URL looks like &year=2006&month=1&day=12
or
URL looks like &date=2006-1-12

Any way you want basically

Then query the database for matching records depending on the date in $_GET.

first way

Code: Select all

$result = mysql_query("SELECT * FROM `table` WHERE `year` = '{$_GET['year']}' AND `month` = '{$_GET['month']}' AND `day` = '{$_GET['day']}'") or die(mysql_error());
second way

Code: Select all

$date = $_GET['date'];
$data = explode("-",$date);
// same query as above basically
It's all up to you on how you want to design it. However if you do plan to archive them, then as the blogs are written you should store the date with them (obviously) or at least a timestamp.

Posted: Tue Feb 21, 2006 10:45 am
by feyd
Initially, I'd spend a bunch of time getting a SQL query down to what I want. After that, I'd write a loop that would do some processing on the results returned calculating the various date ranges. Output would likely be a simple loop with some "change" detection. The changes detected would be things like a change in week, month, or year. Each change would end any previous nest as needed and start a new nest.

Posted: Tue Feb 21, 2006 10:59 am
by m0nk3yb0y
Could you do this in one query?

Posted: Tue Feb 21, 2006 11:01 am
by feyd
You can get all the information you need in a single query yes.

Posted: Tue Feb 21, 2006 11:05 am
by m0nk3yb0y
Right, I think I'm getting it know thanx heaps for the nudge feyd. :D