I am creating a page of articles for a site i'm working on. The current page i'm creating needs a list of articles by date. I want to have it list the year the article was posted as a header then list only the entries for that year underneath. I want to have 2 columns of article titles per row. My query is pulling the proper data but I can't figure out how to get it formatted properly. I have the first title followed by the articles for that year in the same row but the second header ends up in a 3rd column in the same row. Here is my current code. You can view it at http://eagled2.com/archtest.php. Any ideas.
<?
require "config.php";
include 'opendb.php';
echo '<link rel="stylesheet" href="/httest.css" type="text/css">';
include 'hthead.htm';
// queries database
$query8 = mysql_query("SELECT id, title, date_format(date, '%Y') as year, date_format(date, '%b %Y') as seldate FROM htarticles where archived=1 group by year desc order by date desc")
//no query? DIE DIE DIE!
or die("Reason :<br />".mysql_error());
$x = 0; //set counter variable to zero
// lets begin the table
echo '<TABLE WIDTH="90%" BORDER="0">'."\n";
// Loop through result set and display rows
while($row = mysql_fetch_array($query8))
{
//set table rows with 2 table cells
if (!($x % 2)) {
if ($x > 0) {
echo '</tr>';
}
echo '<tr>' . "\n";
}
$x++;
echo '<td><div align="left">'."\n";
echo $row['year'].'</div></t
d></tr>'."\n";
//Begin displaying the 3 story titles underneath the category name
$query9 = mysql_query("SELECT DISTINCT * FROM(SELECT id, title, date_format(date, '%Y') as year, date_format(date, '%b %Y') as seldate FROM htarticles where archived=1 order by date desc)ss where year = $row[year]")
//no query? DIE DIE DIE!
or die("Reason :<br />".mysql_error());
echo '<tr>';
while($row = mysql_fetch_array($query9))
{
echo '<td><a href="'.$self.'?='.$row['seldate'].'">'.$row['title'].'</a></td> ';
}
}
// lets end the table
echo '</tr>'."\n";
echo '</TABLE>'."\n";
?>