|
查看: 1149|回复: 5
|
PHP SEARCH 问题
[复制链接]
|
|
|
有谁知道如何写search 的code吗?
为什么我写的这个,不能display东西的?
<h2>Search Form</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="gender">GENDER</option>
<Option VALUE="shoeName">Shoe Name</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>
<?php
if ($searching =="yes"){
echo "<h3>Search Results</h3><p>";
if ($find == ""){
echo "<p>Please Enter a search term";
exit;
}
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("shoes") or die(mysql_error());
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
$query = mysql_query("SELECT shoeID, brandID,shoeName, shoeSize,colour,price,description,FROM shoes WHERE gender LIKE'%$find%'");
while($result = mysql_fetch_array($query)){
echo $result['gender'];
echo " ";
echo $result['shoeName'];
echo "<br>";
echo "<br>";
echo "<br>";
}
$matches=mysql_num_rows($query);
if ($matches == 0){
echo "Sorry, we can not find an entry to match your query<br><br>";
}
echo "<b>Searched For:</b> " .$find;
}
?> |
|
|
|
|
|
|
|
|
|
|
发表于 26-11-2010 10:03 PM
|
显示全部楼层
本帖最后由 Reader 于 26-11-2010 10:11 PM 编辑
$searching = $_POST["searching"];
$find = $_POST["find"];
if ($searching =="yes"){
echo "<h3>Search Results</h3><p>";
please add the red color code b4 the if statement... |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 26-11-2010 11:40 PM
|
显示全部楼层
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\s\ABC.PHP on line 33
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htdocs\s\ABC.PHP on line 43
Sorry, we can not find an entry to match your query
有error >.< 什么意思啊 |
|
|
|
|
|
|
|
|
|
|
发表于 28-11-2010 12:05 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 30-11-2010 05:00 PM
|
显示全部楼层
你的sql query 有问题.
KidoDeLog 发表于 28-11-2010 12:05 AM 
"SELECT shoeID, brandID,shoeName, shoeSize,colour,price,description,FROM
去掉这个逗号 |
|
|
|
|
|
|
|
|
|
|
发表于 30-11-2010 08:12 PM
|
显示全部楼层
<?php
if (isset($_POST['search'])){
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("shoes") or die(mysql_error());
$find = trim(strip_tags(strtoupper($find)));
$query = mysql_query(sprintf("SELECT shoeID, brandID,shoeName, shoeSize, colour, price, description FROM `shoes` WHERE gender LIKE '%s'", '%'.$find.'%'));
$num_rows = mysql_num_rows($query);
if ($num_rows){
while ($val = mysql_fetch_row($query)){
$result .= $val['gender'].','.$val['shoeName'];;
}
}else{
$result = "Sorry, we can not find an entry to match your query";
}
}
?>
<h2>Search Form</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<select NAME="field">
<option VALUE="gender">GENDER</option>
<option VALUE="shoeName">Shoe Name</option>
</select>
<input type="submit" name="search" value="Search" />
</form>
<h3>Search Results</h3>
<?= $result ?> |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|