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 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    13
    Thanked 0 Times in 0 Posts

    why this code is not giving out any result?

    Code:
    <?php
    mysql_connect ('localhost', 'db_username', 'db_password') ;
    mysql_select_db ('db_name');
    
    if (!isset($_GET['month'])) {
        die("Invalid month specified.");
    }
    else {
        $month = (int)$_GET['month'];
    }
    
    $result = mysql_query("SELECT timestamp, id, title FROM php_blog WHERE FROM_UNIXTIME(timestamp, '%m') = '$month' ORDER BY id DESC");
    
    while ($row = mysql_fetch_array($result)) {
        $date = date("l F d Y", $row['timestamp']);
        $id = $row['id'];
        $title = stripslashes($row['title']);
    
        ?>
    
        <p><?php echo $date; ?><br /><a href="journal.php?id=<?php echo $id; ?>"><?php echo $title; ?></a></p>
        <?php
    }
    
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    There is only two reasons:
    The first is that your query has failed causing your script to err. Check the error logs for PHP, or add
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    To the script to see. If its a failure on the mysql_query, you should be catching the error before trying to process it.

    Second: If no error is caused, the data has no match for the criteria you have given it. The only heads up I can give on that is that %m should be giving you a 0 based month, so january will be 01, so you need to match that against that input from the user.

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    13
    Thanked 0 Times in 0 Posts

    I have checked

    Sir I've myself entered the input. and there is data available in database. I have checked from 01 to 12, Nothing is coming up.
    The same code gives the result if I use %Y....
    I m confused :-( I m new coder practicing codes...You can check it on my website what I mean.

    www.meerab.info/muzammil/mblog.php

    In the archive section It is working if I group data by year, but not by month.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I don't follow links from work.
    That said, the problem is actually easier than I thought, can't believe I missed:
    PHP Code:
    if (!isset($_GET['month'])) {
        die(
    "Invalid month specified.");
    }
    else {
        
    $month = (int)$_GET['month'];

    An integer can never be 0 based. That needs to be reconverted to a string, but I'd still cast:
    PHP Code:
    if (!isset($_GET['month'])) {
        die(
    "Invalid month specified.");
    }
    else {
        
    $month str_pad((int)$_GET['month'], 20STR_PAD_LEFT);

    Try that.

  • Users who have thanked Fou-Lu for this post:

    muzammil (05-16-2011)

  • #5
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    lol Fou i was just about to write the same thing :P

  • #6
    New Coder
    Join Date
    Dec 2010
    Posts
    22
    Thanks
    13
    Thanked 0 Times in 0 Posts
    @FOU You're awsome!!! Thanks for bearing with me!!


  •  

    Posting Permissions

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