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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Month & Day Are Seen As The Same

    Hi all,

    I am working on this php file, and have got it to show me members when I select January, it shows me all the birthdays from January but also extra dayes for e.g. it will add 12/01/1980 BUT also 01/12/1980 becuase it has a 1 and January is equal to 1 in my code, so how can I get it to know what is month?

    PHP Code:
    //assign the bday variable.
    $month = $_REQUEST['month'];

    //birthday search
    $info = mysql_query("SELECT * FROM `tblmembers` WHERE `DateOfBirth` LIKE '%$month%'");

    echo '<table border="1" cellpadding="3" cellspacing="1">
      <tr valign="top">
        <td>First Name</td>
        <td>Last Name</td>
        <td>DateOfBirth</td>
        <td>Last Login</td>
      </tr>';

    if (mysql_num_rows($info) < 1) {
    echo '<tr valign="top">
      <td colspan="4">There are no members that match the query. Please go back and try again</td>
        </tr>';
    }

    else {
       while ($qry = mysql_fetch_array($info)) {

    //create the layout
    ?>
    <link href="cs_style.css" rel="stylesheet" type="text/css" />

      <tr valign="top">
        <td><?php echo $qry['FirstName']; ?></td>
        <td><?php echo $qry['LastName']; ?></td>
        <td><?php echo date('d/m/Y'strtotime($qry['DateOfBirth'])); ?></td>
        <td><?php echo($qry['loginDateTime']?date('d/m/Y H:i:s'strtotime($qry['loginDateTime'])):'N/A'?></td>
      </tr>
    <?php
       
    }
    }

    echo 
    '</table>';
    ?>

  • #2
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    "SELECT * FROM `tblmembers` WHERE `DateOfBirth` LIKE '%$month%'"
    Are you storing the date of birth as a varchar/text?

  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    The Type is 'date'... If that helps...

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    I think you should look into MySQL's date functions then. And not use LIKE, as that is for string searching.

    Almost any birth date will contain $month if it is set to 1, since the year has a 1 in it most likely.

  • #5
    New Coder
    Join Date
    May 2005
    Location
    Leeds, UK
    Posts
    83
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yeah, use "SELECT * FROM `tblmembers` WHERE MONTH(`DateOfBirth`)=%$month"

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by hessodreamy View Post
    yeah, use "SELECT * FROM `tblmembers` WHERE MONTH(`DateOfBirth`)=%$month"
    I tried this but it through out an error on line 25 which is
    PHP Code:
    if (mysql_num_rows($info) < 1) { 

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You need to post the error and the code you used.

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok error is
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in e:\birthdaysearch.php on line 25
    Code is
    PHP Code:
    //assign the bday variable.
    $month = $_REQUEST['month'];

    //birthday search
    $info = mysql_query("SELECT * FROM `tblmembers` WHERE MONTH(`DateOfBirth`)=%$month");

    echo '<table border="1" cellpadding="3" cellspacing="1">
      <tr valign="top">
        <td>First Name</td>
        <td>Last Name</td>
        <td>DateOfBirth</td>
        <td>Last Login</td>
      </tr>';

    if (mysql_num_rows($info) < 1) {
    echo '<tr valign="top">
      <td colspan="4">There are no members that match the query. Please go back and try again</td>
        </tr>';
    }

    else {
       while ($qry = mysql_fetch_array($info)) {

    //create the layout
    ?>
    <link href="cs_style.css" rel="stylesheet" type="text/css" />

      <tr valign="top">
        <td><?php echo $qry['FirstName']; ?></td>
        <td><?php echo $qry['LastName']; ?></td>
        <td><?php echo date('d/m/Y'strtotime($qry['DateOfBirth'])); ?></td>
        <td><?php echo($qry['loginDateTime']?date('d/m/Y H:i:s'strtotime($qry['loginDateTime'])):'N/A'?></td>
      </tr>
    <?php
       
    }
    }

    echo 
    '</table>';
    ?>

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You query is failing, remove the % before $month.


  •  

    Posting Permissions

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