Blog archiving question
Moderator: General Moderators
Blog archiving question
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
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
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.I'm just not sure how to implement this other than hardcoding the html with the date variables myself.
Code: Select all
<?php
if(!empty($_GET['date_var'])){
// some html formatting maybe?
echo "<p>{$_GET['date_var']}</p>";
}Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
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?
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?
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
second way
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.
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());Code: Select all
$date = $_GET['date'];
$data = explode("-",$date);
// same query as above basicallySet Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.