Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2008
    Location
    UK
    Posts
    47
    Thanks
    6
    Thanked 2 Times in 2 Posts

    rookie in need of help with archive code

    Hi, I have a code someone made me a while ago, it works fine on the site I was making back then, but for some reason it doesn't work on the one I'm doing now.

    Its main function is to list all months from now and then when you click a month, show all entries in a database from that month.

    For some reason it is just showing "May 2009" twice and when I click on that it's bringing up nothing (there are entries made in May 2009)

    PHP Code:
    <?
    //get desired month and year
    if (isset($_GET['month']))
    {
        
    $desiredMonth $_GET['month'];
    } else {
        
    $desiredMonth '';
    }
    if (isset(
    $_GET['year']))
    {
        
    $desiredYear $_GET['year'];
    } else {
        
    $desiredYear '';
    }

    if(
    $desiredMonth && $desiredYear)
    {
        
    $db=mysql_connect("*****","*****","*****") or die ('cant connect');
        
    mysql_select_db("*****",$db) or die ("cant change");
        
    $news=mysql_query("SELECT * FROM news WHERE 1 AND date LIKE '%".$desiredMonth."%".$desiredYear."%' ORDER BY id DESC") or die ("cant get table");
        while(
    $rows=mysql_fetch_array($news)){ 
        
    $title=$rows["title"];
    $body=$rows["body"];
    $date=$rows["date"];
    $id=$rows["id"];


    echo 
    "<h3>$title</h3>
            <p>$date</p>
            <p>$body</p>"
    ;
        }
    } else { 

        
    $time1  strtotime('2009-05-06'); 
        
    $time2  strtotime("now"); 
        
    $my     date('mY'$time2); 

           
    $months = array(date('F Y'$time1)); 

           while(
    $time1 $time2) { 
            
    $time1 strtotime(date('Y-m-d'$time1).' +1 month'); 
            if(
    date('mY'$time1) != $my && ($time1 $time2)) 
                 
    $months[] = date('F Y'$time1); 
        } 

           
    $months[] = date('F Y'$time2); 

        foreach (
    $months as $value){
            echo 
    "<a href='archive.php?month=".substr($value03)."&year=".substr($value, -4)."'>".$value."</a>";
        }  
    }
    ?>
    it could be something really simple but I dont actually know php and I cant ask the person who made it originally, I would be very grateful for any help

    ~sb
    ~soapbox

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    This script is expecting a query string containing a month and year value. Are you sending a query string to this script? (A query string is the stuff in a URL that begins with a question mark; for example the URL for the page I'm on right now is "http://codingforums.com/newreply.php?do=newreply&noquote=1&p=813657", so the query string is "?do=newreply&noquote=1&p=813657".)

  • #3
    New Coder
    Join Date
    Aug 2008
    Location
    UK
    Posts
    47
    Thanks
    6
    Thanked 2 Times in 2 Posts
    I'm sorry, I don't really understand this stuff at all, really I'm normally just a graphics person. I thought that the code at the bottom generated links which include the query string?

    the link to May is being generated by the page, but it is being generated twice (no idea why)

    the link points to archive.php?month=May&year=2009

    but the resulting page is blank (despite there being entries in the database dated 2009-05-06)
    ~soapbox

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Ok... Well... I looked at the script a little more closely and it would seem the dates in your table are stored entirely the wrong way, which probably explains why you're not getting any results back. Without changing the script you'll have to store your dates in a ""MM...YYYY"" format. The query is really horrible though and should be changed (along with the way you are storing dates).

  • #5
    New Coder
    Join Date
    Aug 2008
    Location
    UK
    Posts
    47
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Well erm.. the original code is really old (as in, years) and I didn't write it. Thanks anyway at least I know where the problem lies.
    ~soapbox


  •  

    Posting Permissions

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