Page 1 of 1

searching between two dates!

Posted: Wed Dec 25, 2002 5:13 am
by sirTemplar
i have this code to search the a database field between two dates:
$result = mysql_query ("SELECT * FROM mybrothers
WHERE PROFTDAT1 BETWEEN '$begtemp' AND '$endtemp'
AND SDATFIN1 = ' '
AND MORTDAT1 = ' '
ORDER BY PROFTDAT1 ASC, CNOMEN
",$conn);

$resultall = mysql_query ("SELECT * FROM friarsofmconv");

$totalrecs = mysql_num_rows($resultall);
$totalrows = mysql_num_rows($result);

if ($row = mysql_fetch_array($result)) {

do {
echo "<table bgcolor=#35669A border=0 cellpadding=0 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=100%>
<tr><td align=left width=88% valign=top><b><font face=Verdana size=2 color=#0000FF></font></b></td>
<td bgcolor=#FFFFFF align=right width=12% valign=top><b><font face=Verdana size=1 color=#008000>code:</font></b> <font face=Verdana size=1 color=#111111>{$row['IDNUMF']}</td></font></table>";

}
echo ("<p>");
echo ("<p>");
} while($row = mysql_fetch_array($result));
} else {print "Sorry, no records were found!";}
?>
this searches only one fields from a table on the database. however i like to have on my search form the possibility to search other fields on the table, something like:
$result = mysql_query ("SELECT * FROM friarsofmconv
WHERE PROFTDAT1 BETWEEN '$begtemp' AND '$endtemp'
WHERE NATDAT1 BETWEEN '$begbday' AND '$endbday'
AND SDATFIN1 = ' '
AND MORTDAT1 = ' '
ORDER BY PROFTDAT1 ASC, CNOMEN
",$conn);
but this gives me no result or errors! can anyone help :( please, :oops:

Posted: Wed Dec 25, 2002 12:24 pm
by mydimension
not sure of the syntax here but the logic should work:

Code: Select all

SELECT * FROM friarsofmconv
WHERE (PROFTDAT1 BETWEEN '$begtemp' AND '$endtemp')
AND (NATDAT1 BETWEEN '$begbday' AND '$endbday')
AND SDATFIN1 = ' '
AND MORTDAT1 = ' '
ORDER BY PROFTDAT1 ASC, CNOMEN

still wont work!

Posted: Sat Dec 28, 2002 9:43 am
by sirTemplar
is still wont work! :(