Log in

View Full Version : archives in php



why not
02-09-2009, 03:43 PM
hi !
how to creat list or dropdown menu list for monthly archives using php/mysql ?
EXAMPLE :
MARCH 2008
FEBRUARY 2008
APRIL 2008
MAY 2008
.
.
.
.
................
Now if any month not have data . NOTE : not show in list .
thanks regards

Nile
02-10-2009, 02:17 AM
We'd have to see a whole structure. But if you have a timestamp date in your database that either uses the number of the month( 1-12 ), the name of the month ( Jan - Dec ), or a time stamp ( time() ), you could do this.

Can you please tell me what your using first though?

-Nile

why not
02-10-2009, 01:56 PM
yes , save in tiemstamp method .

Nile
02-10-2009, 10:59 PM
Try this(change all the table names & fields to your database and tables).


<?php
if(isset($_GET['arch'])){
connect(); //connect to your database and host

$result = mysql_query("SELECT * FROM `table_name`") or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
if((date("m", $row['timestamp']) == $_GET['arch'])){
echo $row['what_to_display'];
}
}
exit;
}
$months = range(1, 12);
foreach($months as $month){
echo "<a href='?arch=".date("m", mktime(0,0,0,$month))."'>".date("F", mktime(0,0,0,$month))."<br />";
}
?>

why not
02-12-2009, 09:47 AM
<?php
if(isset($_GET['arch'])){
connect(); //connect to your database and host

$result = mysql_query("SELECT * FROM `table_name`") or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
if((date("m", $row['timestamp']) == $_GET['arch'])){
echo $row['what_to_display'];
}
}
exit;
}
$months = range(1, 12);
foreach($months as $month){
echo "<a href='?arch=".date("m", mktime(0,0,0,$month))."'>".date("F", mktime(0,0,0,$month))."<br />";
}
?>
this code list all month in database . without year !!!!!
how to show ONLY month which have data + year
EXAMPLE :

month 1 2008 / month 2 2008 / month 4 2008 / month 7 2008 . . . . . . .
NOTE : month 3 , 5 & 6 not have data so not show in list .