hoofi发给peacock的帖子<? $sql=""; if ($housetype) { $sql="where housetype ='".$housetype."'"; } $sql="where id >0"; $sql=$sql." and addr like '%".$addr."%'"; $sql=$sql." and area between ".$area1." and ".$area2; $sql=$sql." and rent between ".$rent1." and ".$rent2; if (isset($sql)) { session_register($sql); echo $sql; } else { echo "變數沒傳進來"; } $db=mysql_connect("127.0.0.1","root","hufei99") or die ("无法连接MYSQL主机"); mysql_select_db("agency") or die ("无法打开数据库"); ?> <html> <head> </head> <title>房屋中介--分页显示</title> <body> <? include "file1.x"; print $sql; $qh=mysql_query("SELECT COUNT(*) AS rcnt FROM info ".$sql." order BY id"); $data=mysql_fetch_array($qh); $nr=$data["rcnt"]; if (empty($offset)) { $offset=0; } $result=mysql_query("SELECT * FROM info ".$sql." ORDER BY id LIMIT $offset, 20"); ?> <table border="1" cellspacing="0" cellpadding="0" width="580" height="20" align=center> <tr bgcolor="#CCFFCC"> <td height="7" width="35"><font size="2">ID</font></td> <td height="7" width="50"><font size="2">区</font></td> <td height="7" width="90"><font size="2">房屋状况类别</font></td> <td height="7" width="72"><font size="2">租金类别</font></td> <td height="7" width="87"><font size="2">租金(元/月)</font></td> <td height="7" width="54"><font size="2">用户类型</font></td> <td height="7" width="74"><font size="2">房屋面积</font></td> <td height="7" width="100"><font size="2">加入日期</font></td> </tr> <? while ($data=mysql_fetch_array($result)) { ?> <tr> <td height="2" width="35"><a href=all.php?id=<? echo $data[id];?>><? echo $data[id];?></td> <td height="2" width="50"><font size="2"><? echo $data[qu];?></font></td> <td height="2" width="90"><font size="2"><? echo $data[housetype];?></font></td> <td height="2" width="72"><font size="2"><? echo $data[renttype];?></font></td> <td height="2" width="87"><font size="2"><? echo $data[rent];?></font></td> <td height="2" width="54"><font size="2"><? echo $data[usertype];?></font></td> <td height="2" width="74"><font size="2"><? echo $data[area];?></font></td> <td height="2" width="100"><font size="2"><? echo $data[adddate];?></font></td> </tr> <? } if($offset) //如果偏移量是0,不显示前一页的链接 { $preoffset=$offset-20; print "<a href=\"$PHP_SELF?offset=$preoffset\">前一页</a> \n"; } //计算总共需要的页数 $pages=ceil($nr/20); //$pages变量现在包含所需的页数 for ($i=1; $i <= $pages; $i++) { $newoffset=20*$i; print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n"; } //检查是否是最后一页 if ($pages!=0 && ($newoffset/20)!=$pages) { print "<a href=\"$PHP_SELF?offset=$newoffset\">下一页</a> \n"; } ?> </body> </html> ------------------- hoofi 看上去气血充盈,武功很是了得 你如果ask hoofi about 所学专业的话, 他会告诉你:兄弟,我就是那个学计算机应用的,4年苦练才到了 600级,还要段时间我也可以天人合一啦!!
to hoofi: 你这程序有问题,look: if ($housetype) { $sql="where housetype ='".$housetype."'"; } $sql="where id >0"; 分析:$sql永远都等于"where id >0"; 这个程序和你的问题好像不太一样,我还没有看完,我现在有事,等我待会继续
$sql="";
if ($housetype) {
$sql="where housetype ='".$housetype."'";
}
$sql="where id >0";
$sql=$sql." and addr like '%".$addr."%'";
$sql=$sql." and area between ".$area1." and ".$area2;
$sql=$sql." and rent between ".$rent1." and ".$rent2;
if (isset($sql)) {
session_register($sql);
echo $sql;
}
else {
echo "變數沒傳進來";
}
$db=mysql_connect("127.0.0.1","root","hufei99") or die ("无法连接MYSQL主机");
mysql_select_db("agency") or die ("无法打开数据库");
?>
<html>
<head>
</head>
<title>房屋中介--分页显示</title>
<body> <?
include "file1.x";
print $sql;
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM info ".$sql." order BY id"); $data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
if (empty($offset))
{
$offset=0;
}
$result=mysql_query("SELECT * FROM info ".$sql." ORDER BY id LIMIT $offset, 20");
?>
<table border="1" cellspacing="0" cellpadding="0" width="580" height="20" align=center>
<tr bgcolor="#CCFFCC">
<td height="7" width="35"><font size="2">ID</font></td>
<td height="7" width="50"><font size="2">区</font></td>
<td height="7" width="90"><font size="2">房屋状况类别</font></td>
<td height="7" width="72"><font size="2">租金类别</font></td>
<td height="7" width="87"><font size="2">租金(元/月)</font></td>
<td height="7" width="54"><font size="2">用户类型</font></td>
<td height="7" width="74"><font size="2">房屋面积</font></td>
<td height="7" width="100"><font size="2">加入日期</font></td>
</tr>
<?
while ($data=mysql_fetch_array($result))
{
?>
<tr>
<td height="2" width="35"><a href=all.php?id=<? echo $data[id];?>><? echo $data[id];?></td>
<td height="2" width="50"><font size="2"><? echo $data[qu];?></font></td>
<td height="2" width="90"><font size="2"><? echo $data[housetype];?></font></td>
<td height="2" width="72"><font size="2"><? echo $data[renttype];?></font></td>
<td height="2" width="87"><font size="2"><? echo $data[rent];?></font></td>
<td height="2" width="54"><font size="2"><? echo $data[usertype];?></font></td>
<td height="2" width="74"><font size="2"><? echo $data[area];?></font></td>
<td height="2" width="100"><font size="2"><? echo $data[adddate];?></font></td>
</tr>
<?
}
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-20;
print "<a href=\"$PHP_SELF?offset=$preoffset\">前一页</a> \n";
}
//计算总共需要的页数 $pages=ceil($nr/20); //$pages变量现在包含所需的页数 for ($i=1; $i <= $pages; $i++) { $newoffset=20*$i; print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n"; } //检查是否是最后一页 if ($pages!=0 && ($newoffset/20)!=$pages) { print "<a href=\"$PHP_SELF?offset=$newoffset\">下一页</a> \n"; } ?>
</body>
</html>
-------------------
hoofi 看上去气血充盈,武功很是了得
你如果ask hoofi about 所学专业的话,
他会告诉你:兄弟,我就是那个学计算机应用的,4年苦练才到了
600级,还要段时间我也可以天人合一啦!!
你这程序有问题,look:
if ($housetype) {
$sql="where housetype ='".$housetype."'";
}
$sql="where id >0"; 分析:$sql永远都等于"where id >0"; 这个程序和你的问题好像不太一样,我还没有看完,我现在有事,等我待会继续
是要那个值,如果$housetype=0的话,就是id>0 ,这个不是很重要。
可以帮忙看以下么??谢谢!
session_register($sql)
~~~~~~~
改成session_register("sql")
setcookie('cookie_sql', $sql);
和session一样,前面不能有echo,html,print.
不要担心cookie会被关掉,你见过有人把cookie关的吗?