Searching database

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
thoughtriot
Forum Commoner
Posts: 26
Joined: Thu Nov 07, 2002 9:32 pm

Searching database

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Post Reply