Results 1 to 5 of 5

Thread: archives in php

  1. #1
    Join Date
    Feb 2008
    Posts
    62
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default archives in php

    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

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    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
    Jeremy | jfein.net

  3. #3
    Join Date
    Feb 2008
    Posts
    62
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    yes , save in tiemstamp method .

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Try this(change all the table names & fields to your database and tables).
    Code:
    <?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 />";
    	}
    ?>
    Last edited by Nile; 02-10-2009 at 11:20 PM.
    Jeremy | jfein.net

  5. #5
    Join Date
    Feb 2008
    Posts
    62
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <?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 .

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •