...

View Full Version : Month & Day Are Seen As The Same



tomyknoker
03-15-2007, 04:21 PM
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?



//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>';
?>

aedrin
03-15-2007, 04:42 PM
"SELECT * FROM `tblmembers` WHERE `DateOfBirth` LIKE '%$month%'"

Are you storing the date of birth as a varchar/text?

tomyknoker
03-15-2007, 04:44 PM
The Type is 'date'... If that helps...

aedrin
03-15-2007, 04:45 PM
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.

hessodreamy
03-15-2007, 04:50 PM
yeah, use "SELECT * FROM `tblmembers` WHERE MONTH(`DateOfBirth`)=%$month"

tomyknoker
03-15-2007, 04:56 PM
yeah, use "SELECT * FROM `tblmembers` WHERE MONTH(`DateOfBirth`)=%$month"I tried this but it through out an error on line 25 which is
if (mysql_num_rows($info) < 1) {

Inigoesdr
03-15-2007, 05:34 PM
You need to post the error and the code you used.

tomyknoker
03-15-2007, 05:56 PM
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


//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>';
?>

Inigoesdr
03-15-2007, 06:28 PM
You query is failing, remove the % before $month.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum