searching between two dates!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

searching between two dates!

Post 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:
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post 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
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

still wont work!

Post by sirTemplar »

is still wont work! :(
Post Reply