高手给看看这段代码吧,一直报错啊

xujian2009 2010-07-26 10:53:34
<?php

echo"<link rel=\"stylesheet\" type=\"text/css\" href=\"/computer/css/index.css\" />";
echo "<link href=\"index.css\" type=\"text/css\" rel=stylesheet />";

include("head.html");
include("dbinfo.inc.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//echo "连接成功!";
mysql_query("SET NAME 'UTF8'");
mysql_query("SET CHARACTER SET UTF8");
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");



$brand = $_GET['brand'];
//echo "$brand";
if($brand == null){

showLaptops("hp");
echo "1111111";
} else {
showLaptops($brand);

};

function showLaptops($brand){



$query = "SELECT * FROM laptops WHERE name like '"+$brand+"%'";

$result=mysql_query($query);


$num = mysql_num_rows($result);


mysql_close();

echo "<b><center>Laptop Database Output</center></b><br><br>";

$i = 0;

while ($i < $num) {

$name=mysql_result($result,$i,"name");
$price=mysql_result($result,$i,"price");
$time=mysql_result($result,$i,"time");
$img=mysql_result($result,$i,"img");
$weight=mysql_result($result,$i,"weight");

echo "<div class=\"laptop_container\">

<div class=\"laptop_img_container\"><img src=\"/computer/images/$img\"></img></div>

<div class=\"laptop_content\">

<ul><li>name:$name</li>
<li>price: $price</li>
<li>time: $time</li>
<li>weight: $weight</li>
</ul>
</div>

</div>";
$i++;
}

}

echo " <div class=\"index_menu_container\">
<ul>
<li id=\"index_button_hp\"><a class=\"container_hp\" href=\"index.php?brand=hp\" ><span>HP</span></a></li>
<li id=\"index_button_apple\"><a class=\"container_apple\" href=\"index.php?brand=apple\" ><span>APPLE</span></a></li>
<li id=\"index_button_lenovo\"><a class=\"container_lenovo\" href=\"index.php?brand=lenovo\" ><span>LENOVO</span></a></li>
<li id=\"index_button_hasee\"><a class=\"container_hasee\" href=\"index.php?brand=hasee\" ><span>HASEE</span></a></li>
<li id=\"index_button_dell\"><a class=\"container_dell\" href=\"index.php?brand=dell\" ><span>DELL</span></a></li>
</ul>
</div> ";

include("foot.html");

?>

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\www\computer\index.php on line 38 就是这行 $num = mysql_num_rows($result);
...全文
28 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xujian2009 2010-07-27
[Quote=引用 1 楼 amani11 的回复:]
$query = "SELECT * FROM laptops WHERE name like '"+$brand+"%'";

改成这样试试

echo "SELECT * FROM laptops WHERE name like '%" . $brand . "%'";
[/Quote]

谢谢你啊,确实是那里的问题。
回复
amani11 2010-07-26
$query = "SELECT * FROM laptops WHERE name like '"+$brand+"%'";

改成这样试试

echo "SELECT * FROM laptops WHERE name like '%" . $brand . "%'";
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告