timmy0320 wrote:Yeah, I pretty much jacked mine all up. Back to square one. The foreach you use gives me an error.
That's odd as I checked the script before pasting it.
I'll find and post the script as a zip file.
Ok I found the script and all the code is the same as posted.
I ran the script again just to make sure it didn't error.
Whew it is ok.
Obviously you have to change the database details from mine to yours.
UMM, here's a thought give me your db details on what you're wanting and let me change the script for your needs.
Just a thought.
Here's a variation similar to your post above
January 2008 [ 2 ]
Jan_1_2008
Jan_2_2008
February 2008 [ 2 ]
Feb_5_2008
Feb_9_2008
March 2008 [ 1 ]
Mar_5_2008
April 2008 [ 5 ]
Apr_2_2008
Apr_3_2008
Apr_4_2008
Apr_5_2008
Apr_6_2008
<?php
include("your db connection script");
$query = "SELECT ArchiveID from Archive where validate='1'";
$result = mysql_query($query) or die ("can not select from Archive");
//we add this line because we need to know the number of active Archive Months
$num_rows = mysql_num_rows($result);
echo "<table><tr>";
//changed this to a for loop so we can use the number of active Archive Months found
for($i = 0; $i < $num_rows; $i++) {//1
$row = mysql_fetch_array($result);
$cat = stripslashes($row['ArchiveID']);
$getmaincats="SELECT * from Archive where ArchiveID='$cat' order by ArchiveDate asc";
$getmaincats2=mysql_query($getmaincats) or die("Could not get root Archive");
//print "<tr>";
while($row=mysql_fetch_array($getmaincats2))
{//3
$ArchiveID = stripslashes($row['ArchiveID']);
$ArchiveDate = stripslashes($row['ArchiveDate']);
$Archives = stripslashes($row['ArchiveDate']);
$ArchiveDate = str_replace(" & ","_-_",$ArchiveDate);
$ArchiveDate = str_replace("_"," ",$ArchiveDate);
$ArchiveDates = str_replace(" ","_",$ArchiveDate);
// Print the Archive Date as the Header for each new month.
print "<td><font face='arial' size=1><A href='http://www.yourdomain.com/blog/Archives/$ArchiveDates' target='MAIN' TITLE='View Posts by Month'><b>$ArchiveDate</b></a>";
$query_count = "SELECT * FROM Archive inner join advert_rss on Archive.ArchiveID = advert_rss.ArchiveID where Archive.ArchiveID = '$ArchiveID' order by advert_rss.ArchiveID ASC";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count); // Gets the number of articles per month
// Print the total posts next to Header as [2]
print" [ $totalrows ]</font></td></tr>";
for($i = 0; $i < $totalrows; $i++) {//4
$row = mysql_fetch_array($result_count);
$link = stripslashes($row['link']);
$title = stripslashes($row['title']);
$gettitle = stripslashes($row['title']);
$link= str_replace("-","_",$link);
$title = str_replace(" ","_",$title);
// Print the dates of each posts under the correct Month Header.
print "<TR><TD> <font face='arial' size=1><A href='http://www.yourdomain.com/blog/$link/$title.html' TITLE='View Posts by Date Written'><b>$link</b></a></font></TD></TR>";
}//4
}//3
}//1
echo("</table>");
?>
You have to remember to change the db fields so they match what you are using.
to help you out here's a copy of the table structure for the tables I am using.
CREATE TABLE advert_rss (
id int(5) unsigned NOT NULL auto_increment,
ArchiveID int(5) NOT NULL,
title varchar(80) default '',
link varchar(200) NOT NULL default '',
comments varchar(256) NOT NULL,
description text,
keywords varchar(156) NOT NULL,
body blob NOT NULL,
author varchar(80) NOT NULL,
category varchar(80) NOT NULL,
guid varchar(156) NOT NULL,
sourceurl varchar(156) NOT NULL,
sourcelink varchar(156) NOT NULL,
pubdate varchar(50) default NULL,
imageurl varchar(120) NOT NULL default '',
imagetitle varchar(200) NOT NULL default '',
imagelink varchar(120) NOT NULL default '',
imp int(5) NOT NULL default '0',
PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=1 ;
CREATE TABLE Archive (
ArchiveID int(5) unsigned NOT NULL auto_increment,
ArchiveDate varchar(30) NOT NULL,
validate int(1) NOT NULL default '0',
PRIMARY KEY (ArchiveID)
) ENGINE=InnoDB AUTO_INCREMENT=1 ;
Again hope this helps.
Arty