Searching Archives

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thoughtriot
Forum Commoner
Posts: 26
Joined: Thu Nov 07, 2002 9:32 pm

Searching Archives

Post by thoughtriot »

http://www.thoughtriot.net/index.php?z=news.php

I have a little pulldown menu where you can search the archives of news. The problem is, when you search them, it has to go to search.php. I want to be able to search using news.php.

Code: Select all

<p align="center" class="header1">News</p>
<form method="post" action="?z=search.php">
<select name="month" class=inputbox>
<option value="01.">January</option>
<option value="02.">February</option>
<option value="03.">March</option>
<option value="04.">April</option>
<option value="05.">May</option>
<option value="06.">June</option>
<option value="07.">July</option>
<option value="08.">August</option>
<option value="09.">September</option>
<option value="10.">October</option>
<option value="11.">November</option>
<option value="12." selected>December</option>
</select>
<select name="year" class=inputbox>
<option value=".03" selected>2003</option>
<option value=".02" selected>2002</option>
</select>
<input type="submit" class=searchbox value="Go">
</form>
<?
include("news/connect.php");
$month = "" . date(m) . ".";
$year = "." . date(y) . "";
$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>" . nl2br($Entry) . "</td></tr></table><br>";
}
?>
I have that so far.
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

well

Post by lostboy »

assuming the page displayed was news.php

then just change this

<form method="post" action="?z=search.php">

to

<form method="post" action="news.php">

then alter the code of the page to see if the submit button was hit

<?
if (!isset($_POST['submit']){
show the choose date form
}else{
execute the code to pull the relevant data from the db
}

?>

hth
Post Reply