Page 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: Search Members By Birthday

  1. #1
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Search Members By Birthday

    Hi wondering if anyone can help me, I have a list of members in a MySQL db. I want to have an initial page which just has a drop down menu, which lists all the months of the year. From this say I select February in the drop down menu I want it to list all the members with birthdays in February... I only need it to display the members FirstName, LastName, State and DateOfBirth in the outputted table... Any help would be greatly appreciated!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could try something like this in your sql query (after the form has been submitted.

    Code:
    $sql = "SELECT * FROM `table` WHERE `birthday` LIKE '%$bday%'";
    
    $result = mysql_query($sql);
    $bday is the variable assigned by the form choice that has been submitted. Change the parts in red above to work on your db.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yea I think that would be good... so something like this? Is it good to have that else statement under all of it?
    Code:
    <?php
    
    /* connect to the mysql database and use a query to get the members info */
    
    include 'library/config.php';
    include 'library/opendb.php';
    //navigation
    include("nav.php");
    
    //birthday search
    $sql = "SELECT * FROM `table` WHERE `birthday` LIKE '&#37;$bday%'";
    
    $result = mysql_query($sql);
    
    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 $qry['DateOfBirth']; ?></td>
        <td><?php echo $qry['State']; ?></td>
      </tr>
    <?php
       }
    }
    
    echo '</table>';
    ?>

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    That would work if you had another page display the form and submit to the page that the code you posted above is in. So it would look something like this:

    Code:
    <form action="search.php" method="POST">
    Date: <input type="text" name="bday" value="March" readonly>
    <input type="submit" value="Do Search">
    </form>
    Then search.php would be like this (modified version of your above posted code):

    Code:
    <?php
    
    /* connect to the mysql database and use a query to get the members info */
    
    include 'library/config.php';
    include 'library/opendb.php';
    //navigation
    include("nav.php");
    
    $bday = $_POST['bday']; //assign the bday variable.
    
    //birthday search
    $sql = "SELECT * FROM `table` WHERE `birthday` LIKE '&#37;$bday%'";
    
    $info = mysql_query($sql);
    
    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 $qry['DateOfBirth']; ?></td>
        <td><?php echo $qry['State']; ?></td>
      </tr>
    <?php
       }
    }
    
    echo '</table>';
    ?>
    Hope this helps.
    Last edited by thetestingsite; 03-14-2007 at 03:26 AM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok I received this error
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in e:\inetpub\esvc000208\admin\birthdaysearch.php on line 25

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Sorry about that, view my edit in the above code (search.php) in blue. Or in other words, change

    Code:
    $result = mysql_query
    to

    Code:
    $info = mysql_query
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmmm I still get the same error output...

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Ok, did you change the details in this section?

    Code:
    $sql = "SELECT * FROM `table` WHERE `birthday` LIKE '&#37;$bday%'"
    You need to change "table" to your database table name and "birthday" to what field you want the search to be executed in.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Apr 2006
    Posts
    584
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have a feeling I have done this wrong
    Code:
    <html>
    <head>
    <title>Search Birthdays</title>
    </head>
    <body>
    
    <?php
    //navigation
    include("nav.php");
    ?>
    
    <form action="birthdaysearch.php" method="POST">
    <label>
    <select name="bday">
      <option>Select A Month</option>
      <option value="January">January</option>
      <option value="February">February</option>
      <option value="March">March</option>
      <option value="April">April</option>
      <option value="May">May</option>
      <option value="June">June</option>
      <option value="July">July</option>
      <option value="August">August</option>
      <option value="September">September</option>
      <option value="October">October</option>
      <option value="November">November</option>
      <option value="December">December</option>
    </select>
    </label>
    <input type="submit" value="Do Search">
    </form>
    </body>
    </html>

  10. #10
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    How is the "birthday" field in your database formed? In other words, is it plain text (January 15, 1992), timestamp (1123411127), or something else?

    This is important to know before rewritting the code for it to work.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

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
  •