|
Posted by caine on 02/09/07 14:01
I'm doing a search application for my project. My code can prompt
alert popup window when the user doesn't key in any keywords. However,
if the user keys in any keywords, it juz return "Please enter
keywords!" whatever it is. I had set proper looping for suitable
condition checking, but it is still generate the same problem.
<html>
<head>
<title>Searching Results</title>
</head>
<body background="abstract.gif">
<link rel="STYLESHEET" type="text/css" href="stylesheet.css">
<?php
echo "<h1>Searching Results</h1>";
//perform search
if($_POST['submit'] == "")
{
echo "post";
//if(isset($_POST['submit']))
//{
$db = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("bulletin", $db) or die(mysql_error());
$searchWords = explode(" ", $_POST['textfield']);
foreach ($searchWords as $word)
{
if ($word)
{
$whereParts[] = "`TITLE` LIKE '%{$word}%' OR `DEPARTMENT` LIKE '%
{$word}%'" ;
}
}
$whereClause = implode(" OR ", $whereParts);
$query = "SELECT * FROM `bul_data` WHERE {$whereClause} ORDER by
`DATE`";
$res = mysql_query($query) or die(mysql_error());
echo "query=".$query;
if(mysql_num_rows($res)>0)
{
echo "<table width=\"100%\" border=\"1\">";
echo "<tr>";
echo "<th class=\"normal\">Date</th>";
echo "<th class=\"normal\">Title</th>";
echo "<th class=\"normal\">Department</th>";
echo "<th class=\"normal\">Link</th>";
echo "</tr>";
while($row=mysql_fetch_assoc($res))
{
$date = $row['DATE'];
$date = decode($date);
$title = $row['TITLE'];
$title = decode($title);
$department = $row['DEPARTMENT'];
$department = decode($department);
$link = $row['LINK'];
$link = decode($link);
echo "<tr>";
echo "<td><strong>$date</strong></td>";
echo "<td><strong>$title</strong></td>";
echo "<td>$department</td>";
echo "<td><a href = \"$link\">$link</a></td>";
echo "</tr>";
}
echo "</table>";
}
//}
}
else
{
echo "38292930";
echo "Please enter keywords!";
//echo "<script language=\"JavaScript\">
//<!--
//alert('Please enter keywords!');
//-->
//</script>";
}
//function decode($string)
//{
// $string = str_replace("&", "&", $string);
// $string = str_replace("<", "<", $string);
// $string = str_replace(">", ">", $string);
// $string = str_replace("'", "'", $string);
// $string = str_replace(""", "\", $string);
//
// return $string;
//}
function decode($text)
{
$text = html_entity_decode($text,ENT_QUOTES);
return $text;
}
?>
<br>
<table width ="100%" border ="0" cellspacing ="1" cellpadding ="2">
<tr>
<td class="normal" width ="10%" align ="center"><a href =
"homepg.php">Home | </a><a href =
"search.php">Search Again?</a></td>
</tr>
</table>
</body>
</html>
[Back to original message]
|