Page 1 of 1

Searching database

Posted: Sat Nov 30, 2002 7:04 pm
by thoughtriot
http://www.thoughtriot.net/?z=news.php

I'm trying to do an archiving of the news entries. I'm using this code:

Code: Select all

<p align="center" class="header1">News</p>
<form method="post" action="?z=search.php">
<select name="month" class=inputbox>
<option>News Archives
<option  value="11.">November</option>
<option  value="12.">December</option>
</select>
<select name="year" class=inputbox>
<option>News Archives
<option  value=".02">2002</option>
</select>
<input type="submit" class=searchbox value="Go">
</form>
<?
include("news/connect.php");

$result = mysql_query ("SELECT * FROM news WHERE Date LIKE '%$month%' '%$year%' ORDER BY id DESC");
while($r=mysql_fetch_array($result))
{   
$Entry=stripslashes($rї"Entry"]);
$Title=stripslashes($rї"Title"]);
$Name=stripslashes($rї"Name"]);
$Date=stripslashes($rї"Date"]);
$Time=stripslashes($rї"Time"]);
$Email=stripslashes($rї"Email"]);

echo "<table width=95% cellpadding=0 cellspacing=0><tr><td><span class=header2>$Title</span> by <a href=mailto:$Email>$Name</a> on <span class=dates>$Date</span> at <span class=dates>$Time</span></td></tr><tr><td>$Entry</td></tr></table><br>";
}

?>
When I do a search though, if I select November as the month, the entry for 12.11.02 (December) comes up still, since it matches the query, which would search for 11 and 02. Can someone help me with this?

Posted: Sun Dec 01, 2002 1:09 am
by volka
you can perform date-based WHERE-clauses with mysql
take a look at http://www.mysql.com/doc/en/Date_and_ti ... tions.html