我想实现单击不同的按钮,传递不同的参数,显示不同的结果

xujian2009 2010-07-26 09:45:57
代码如下:
index.php

<?php

include("dbinfo.inc.php");


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> ";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

mysql_query("SET NAME 'UTF8'");
mysql_query("SET CHARACTER SET UTF8");
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");

if($_GET('brand')== 'hp'&& $_GET('brand')== ''){
$query="SELECT * FROM laptop where name like 'HP%'";
$result=mysql_query($query);

$num=mysql_numrows($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++;
}
}

if($_GET('brand')== 'apple'){
$query="SELECT * FROM laptop where name like 'Apple%'";
$result=mysql_query($query);

$num=mysql_numrows($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++;
}
}
if($_GET('brand')== 'hp'&& $_GET('brand')== ''){
$query="SELECT * FROM laptop where name like 'HP%'";
$result=mysql_query($query);

$num=mysql_numrows($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++;
}
}}
单是提示有问题啊。Fatal error: Function name must be a string in D:\www\computer\index.php on line 27。
php如何从url来传参数和获取参数啊。高手帮忙看下吧,谢谢了。
我这样写对吗?if($_GET('brand')== 'hp'&& $_GET('brand')== '')。
...全文
69 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xujian2009 2010-07-26
[Quote=引用 2 楼 amani11 的回复:]
if($_GET('brand')== 'hp'&& $_GET('brand')== '')
{
}
//也不能说错,但是这个条件,大概只有一种情况是会执行,花括弧里的代码

那就是
if(0 == 'hp' && 0 == '')
{
echo 1;//这种情况会打印1,
}



27行是哪一行呢,你的代码乱啊。。。



$……
[/Quote]

是啊,没有调好,按照你的要求改了啊。可是,还是不行啊。
回复
gumwzg 2010-07-26
[Quote=引用 1 楼 cunningboy 的回复:]
PHP code
if($_GET['brand']== 'hp'&& $_GET['brand']== '')
[/Quote]
++
回复
amani11 2010-07-26
if($_GET('brand')== 'hp'&& $_GET('brand')== '')
{
}
//也不能说错,但是这个条件,大概只有一种情况是会执行,花括弧里的代码

那就是
if(0 == 'hp' && 0 == '')
{
echo 1;//这种情况会打印1,
}



27行是哪一行呢,你的代码乱啊。。。



$num=mysql_numrows($result);//这个除非你单独定义过,,通常应该是$num=mysql_num_rows($result);
回复
CunningBoy 2010-07-26
if($_GET['brand']== 'hp'&& $_GET['brand']== '')
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

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