This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » PHP » News Archive table using PHP and MySQL
Reply

News Archive table using PHP and MySQL

Vernon Large
Member



Since: 20 Mar 2010
Posts: 1
Posted 21 Mar 2010 03:03:18

Hi,

I need a little advice and hope someone can help!

I am creating a page to enable the visitor to look at older news items and I want to create a table that shows that resembles this

Year JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
2005 X X X X X
2007 X X X X X X X
2008 X X X X X X
2009 X X
2010 X X

My database table (news_table) has the following fields

id
newsDate (Format YYYY-MM-DD)
newstitle
newsInfo
photo
caption
update

In the table, I only want years to show if there is actually a news item in the DB table corresponding to that year and also only an X is shown under the month if a record for that year/month is available. If an X is shown, I want it to like to a page that shows all the records for that year/month!

Any pointers would be helpful

Cheers

Phil

Hi,

I need a little advice and hope someone can help!

I am creating a page to enable the visitor to look at older news items and I want to create a table that shows that resembles this

Year JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
2005 X X X X X
2007 X X X X X X X
2008 X X X X X X
2009 X X
2010 X X

My database table (news_table) has the following fields

id
newsDate (Format YYYY-MM-DD)
newstitle
newsInfo
photo
caption
update

In the table, I only want years to show if there is actually a news item in the DB table corresponding to that year and also only an X is shown under the month if a record for that year/month is available. If an X is shown, I want it to like to a page that shows all the records for that year/month!

Any pointers would be helpful

Cheers

Phil
Roddy Dairion
Zone Manager



Since: 12 Oct 2005
Posts: 441
Replied 30 Mar 2010 15:31:39
I don't know if you've fixed this or not but i have this for you if it helps (FYI i haven't tested any of it, if there's any errors you can't debug just reply back i will try and fix it)

<table border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td>News</td>
		<td>Jan</td>
		<td>Feb</td>
		<td>Mar</td>
		<td>Apr</td>
		<td>May</td>
		<td>June</td>
		<td>July</td>
		<td>Aug</td>
		<td>Sep</td>
		<td>Oct</td>
		<td>Nov</td>
		<td>Dec</td>
	</tr>
<?php
$query="select date_format(newsDate,'%Y') as `News_Year`,newsDate from news_table group by `News_Year`";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
	<tr>
		<td><?php echo $row['News_Year'];?></td>
		
<?php
	for($i=0;$i < 12;$i++)
	{
		$date=explode('-',date("Y-01-d"));
		$checkdate=date("Y-m",mktime(0,0,0,$date[1]+$i,$date[2],$date[0]));
		$query2="select date_format(newsDate,'%Y-%m') as `News_Year` from news_table where `News_Year` = '".$checkdate."'";
		$result2=mysql_query($query2);
		if(mysql_num_rows($result2) > 0)
		{
?>
			<td>X</td>
<?php
		}else{
?>
			<td>&nbsp;</td>
<?php
		}
	}	
?>
	</tr>
<?php
}
?>
</table>



Edited by - Roddy Dairion on 30 Mar 2010  15:33:13

Reply to this topic

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency