为什么php+mysql查询数据的时候无反应,也不报错?
<?phprequire('connect.php');include('head.php');$sql="selectdistinct(firstMesID)fromu...
<?php
require('connect.php');
include('head.php');
$sql="select distinct (firstMesID) from user";
$result=mysql_query($sql,$con);
$num=mysql_num_rows($result);
$page_size=20;
if($num<=$page_size){
$page_count=1;
}
if($num%$page_size){
$page_count=(int)($num/$page_size)+1;
}else{
$page_count=$num/$page_size;
}
if(isset($_GET['page'])){
$page=intval($_GET['page']);
}else{
$page=1;
}
echo "<tr><td align=center><table width='100%'><tr><td align=center>";
if($page_count>1){
echo "页数:";
for($j=1;$j<=$page_count;$j++){
if($j==$page){
echo "$j ";
}
else{
echo "<a href=?page=$j>$j</a>";
}
}
echo "</td></tr></table></td></tr>";
}
echo "<tr><td>";
$sqlpage="select * from user where lastMesID is null order by id desc limit ".($page-1)*$page_size.",$page_size";
$re_page=mysql_query($sqlpage,$con) or die ("查询数据库失败:".mysql_error());
echo "<table border=0 width='80%' align=center>";
echo "<th>标题</th>";
echo "<th>作者</th>";
echo "<th>发帖时间</th>";
echo "<th>回复次数</th>";
while($row=mysql_fetch_array($re_page)){
$len=strlen($row['content']);
$reply_sql="select * from user where firstMesID='$row[id]'";
$reply=mysql_query($reply_sql,$con);
$all_times=mysql_num_rows($reply);
$reply_times=$all_times-1;
echo "<tr><td width='45%'><a href=display.php?mesid=$row[id]>$row[title] ($len 字节)</a></td>";
echo "<td width='10%' align=center>$row[username]</td>";
echo "<td width='30%'>$row[posttime]</td>";
echo "<td width='15%' align=center>$reply_times</td></tr>";
}
echo "</table>";
echo "<tr><td align=center><table width='100%'><tr><td align='center'>";
if($page_count>1){
echo "页数:";
for($j=1;$j<=$page_count;$j++){
if($j==$page){
echo "$j ";
}
else{
echo "<a href=?page=$j>$j></a>";
}
}
echo "</td></tr></table></td></tr>";
}
?>
为什么没反应啊?求大神解答,救急! 展开
require('connect.php');
include('head.php');
$sql="select distinct (firstMesID) from user";
$result=mysql_query($sql,$con);
$num=mysql_num_rows($result);
$page_size=20;
if($num<=$page_size){
$page_count=1;
}
if($num%$page_size){
$page_count=(int)($num/$page_size)+1;
}else{
$page_count=$num/$page_size;
}
if(isset($_GET['page'])){
$page=intval($_GET['page']);
}else{
$page=1;
}
echo "<tr><td align=center><table width='100%'><tr><td align=center>";
if($page_count>1){
echo "页数:";
for($j=1;$j<=$page_count;$j++){
if($j==$page){
echo "$j ";
}
else{
echo "<a href=?page=$j>$j</a>";
}
}
echo "</td></tr></table></td></tr>";
}
echo "<tr><td>";
$sqlpage="select * from user where lastMesID is null order by id desc limit ".($page-1)*$page_size.",$page_size";
$re_page=mysql_query($sqlpage,$con) or die ("查询数据库失败:".mysql_error());
echo "<table border=0 width='80%' align=center>";
echo "<th>标题</th>";
echo "<th>作者</th>";
echo "<th>发帖时间</th>";
echo "<th>回复次数</th>";
while($row=mysql_fetch_array($re_page)){
$len=strlen($row['content']);
$reply_sql="select * from user where firstMesID='$row[id]'";
$reply=mysql_query($reply_sql,$con);
$all_times=mysql_num_rows($reply);
$reply_times=$all_times-1;
echo "<tr><td width='45%'><a href=display.php?mesid=$row[id]>$row[title] ($len 字节)</a></td>";
echo "<td width='10%' align=center>$row[username]</td>";
echo "<td width='30%'>$row[posttime]</td>";
echo "<td width='15%' align=center>$reply_times</td></tr>";
}
echo "</table>";
echo "<tr><td align=center><table width='100%'><tr><td align='center'>";
if($page_count>1){
echo "页数:";
for($j=1;$j<=$page_count;$j++){
if($j==$page){
echo "$j ";
}
else{
echo "<a href=?page=$j>$j></a>";
}
}
echo "</td></tr></table></td></tr>";
}
?>
为什么没反应啊?求大神解答,救急! 展开
1个回答
展开全部
问题多多,阁下是初学PHP吧。
主要问题出在
$reply_sql="select * from user where firstMesID='$row[id]'";
这一行,其中的$row[id]写法错误,里面的id因为代码字符串,所以要加引号,修改如下:
$reply_sql="select * from user where firstMesID='".$row["id"]."'";
粗略看了一下,还有其它地方有问题,这么大一篇,谁愿意仔细地看啊。
你还是多看看基本规则吧,把基础语法弄懂了,晓得大概哪个位置错了,然后细问。
追问
谢谢,我已经解决了!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询