Reply to search queries

Your name:

Reply:


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("&amp;", "&", $string);
// $string = str_replace("&lt;", "<", $string);
// $string = str_replace("&gt;", ">", $string);
// $string = str_replace("&#039;", "'", $string);
// $string = str_replace("&quot;", "\", $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&nbsp;&nbsp;|&nbsp;&nbsp;</a><a href =
"search.php">Search Again?</a></td>

</tr>
</table>


</body>
</html>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация