就是嵌套循环的问题,我在循环中加入第二个循环就出错了!!!帮忙看看,谢谢!!!
<?
$where="";
$linkurl="?";
if (!isset($_GET["p"]) || $_GET["p"]=="")
$p=1; //当前第几页
else
$p=$_GET["p"];
$lines=100; //每页显示的记录数
$start=($p-1)*$lines;//定位当前的第一条记录
$cmd->Open();
$nr = $cmd->ExecuteReader("SELECT cat_id,cat_name FROM shop_category where parent_id=0 ");
//$cmd->Close();
if($nr->rows<1){
echo "<p><div align=center><font color=red>暂无数据!</font></div></p>";
}else{
$nr->Move($start);
$i=$start;
$end=$start+$lines;
//循环出当前页的记录?>
<?
while ($i<$end)
{
if ($nr->Read())
{
?>
<a href='category.php?id=<?=$nr->GetData("cat_id")?>' target="_blank">
<?=$nr->GetData("cat_name")?>
</a> <br>
<?//=======就是这里的循环体,加入就出错了======================$cmd2->Open();
$nr2 = $cmd2->ExecuteReader("SELECT * FROM shop_brand where cat_id=".$nr->GetData("cat_id"));
$cmd2->Close();echo '======'.$nr2->rows;
exit;//循环出当前页的记录
//while ($nr2->Read())while($row=mysql_fetch_array($nr2))
{
?>
<a href='brand.php?id=?=$row["brand_id"]?>' target="_blank">
<?=$row["brand_name"]?> |
</a>
<?
}//==========嵌套循环结束============================
?>
<?
$where="";
$linkurl="?";
if (!isset($_GET["p"]) || $_GET["p"]=="")
$p=1; //当前第几页
else
$p=$_GET["p"];
$lines=100; //每页显示的记录数
$start=($p-1)*$lines;//定位当前的第一条记录
$cmd->Open();
$nr = $cmd->ExecuteReader("SELECT cat_id,cat_name FROM shop_category where parent_id=0 ");
//$cmd->Close();
if($nr->rows<1){
echo "<p><div align=center><font color=red>暂无数据!</font></div></p>";
}else{
$nr->Move($start);
$i=$start;
$end=$start+$lines;
//循环出当前页的记录?>
<?
while ($i<$end)
{
if ($nr->Read())
{
?>
<a href='category.php?id=<?=$nr->GetData("cat_id")?>' target="_blank">
<?=$nr->GetData("cat_name")?>
</a> <br>
<?//=======就是这里的循环体,加入就出错了======================$cmd2->Open();
$nr2 = $cmd2->ExecuteReader("SELECT * FROM shop_brand where cat_id=".$nr->GetData("cat_id"));
$cmd2->Close();echo '======'.$nr2->rows;
exit;//循环出当前页的记录
//while ($nr2->Read())while($row=mysql_fetch_array($nr2))
{
?>
<a href='brand.php?id=?=$row["brand_id"]?>' target="_blank">
<?=$row["brand_name"]?> |
</a>
<?
}//==========嵌套循环结束============================
?>
-------------------------<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><?php
//数据库连接
@include ("config/hnhc_db.php");
?><style type="text/css">
<!--
a:visited {
font-size: 12px;
color: #333333;
text-decoration: none;
}
a:hover {
font-size: 12px;
color: #FF0000;
text-decoration: none;
}
a:link {
font-size: 12px;
color: #990000;
text-decoration: none;
}
-->
</style>
<STYLE>
BODY {
SCROLLBAR-3DLIGHT-COLOR: #fcfcd8;
SCROLLBAR-ARROW-COLOR: #fc9048;
SCROLLBAR-DARKSHADOW-COLOR: #fcfcfc;
SCROLLBAR-BASE-COLOR: #fcb4b4
}
</STYLE>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div style="width:120px;">
<table> <tr>
<td> <?
$where="";
$linkurl="?";
if (!isset($_GET["p"]) || $_GET["p"]=="")
$p=1; //当前第几页
else
$p=$_GET["p"];
$lines=100; //每页显示的记录数
$start=($p-1)*$lines;//定位当前的第一条记录
$cmd->Open();
$nr = $cmd->ExecuteReader("SELECT cat_id,cat_name FROM shop_category where parent_id=0 ");
//$cmd->Close();
if($nr->rows<1){
echo "<p><div align=center><font color=red>暂无数据!</font></div></p>";
}else{
$nr->Move($start);
$i=$start;
$end=$start+$lines;
//循环出当前页的记录?>
<?
while ($i<$end)
{
if ($nr->Read())
{
?>
<img src="themes/kids/images/icon.gif" /><a href='category.php?id=<?=$nr->GetData("cat_id")?>' target="_blank">
<?=$nr->GetData("cat_name")?>
</a> <br>
<?//=============================$cmd2->Open();
$nr2 = $cmd2->ExecuteReader("SELECT * FROM shop_brand where cat_id=".$nr->GetData("cat_id"));
$cmd2->Close();echo '======'.$nr2->rows;
exit;//循环出当前页的记录
while ($nr2->Read())//while($row=mysql_fetch_array($nr2))
{
?>
<a href='brand.php?id=?=$row["brand_id"]?>' target="_blank">
<?=$row["brand_name"]?> |
</a>
<?
}//======================================
?> <?
}
$i++;
}
?> <?
//PageLine($nr->rows,$lines,$linkurl,$p,1);
?>
<?
}
?>
</td>
</tr>
</table></div>
如果有循环里面的内容的话就是html格式不对,没内容的话就是程序有问题了。
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?php
//数据库连接
@include ("config/hnhc_db.php");
?>
<style type="text/css">
<!--
a:visited {
font-size: 12px;
color: #333333;
text-decoration: none;
}a:hover {
font-size: 12px;
color: #FF0000;
text-decoration: none;
}a:link {
font-size: 12px;
color: #990000;
text-decoration: none;
}
-->
</style>
<STYLE>
BODY {
SCROLLBAR-3DLIGHT-COLOR: #fcfcd8;
SCROLLBAR-ARROW-COLOR: #fc9048;
SCROLLBAR-DARKSHADOW-COLOR: #fcfcfc;
SCROLLBAR-BASE-COLOR: #fcb4b4
}
</STYLE>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div style="width: 120px;">
<table>
<tr>
<td><?
$where="";
$linkurl="?";
if (!isset($_GET["p"]) || $_GET["p"]==""){
$p=1; //当前第几页
}else{
$p=$_GET["p"];
}
$lines=100; //每页显示的记录数
$start=($p-1)*$lines;//定位当前的第一条记录
$cmd->Open();
$nr = $cmd->ExecuteReader("SELECT cat_id,cat_name FROM shop_category where parent_id=0 ");
//$cmd->Close();
if($nr->rows <1){
echo " <p> <div align=center> <font color=red>暂无数据! </font> </div> </p>";
}else{
$nr->Move($start);
$i=$start;
$end=$start+$lines; //循环出当前页的记录
while ($i <$end){
if ($nr->Read()){
?> <img src="themes/kids/images/icon.gif" /> <a
href='category.php?id= <?=$nr->GetData("cat_id")?>' target="_blank">
<?=$nr->GetData("cat_name")?> </a> <br>
<? //============================= $cmd2->Open();
$nr2 = $cmd2->ExecuteReader("SELECT * FROM shop_brand where cat_id=".$nr->GetData("cat_id"));
//$cmd2->Close(); echo '======'.$nr2->rows;
exit; //循环出当前页的记录
while ($nr2->Read()){ //while($row=mysql_fetch_array($nr2)){
?> <a href='brand.php?id=<?=$row["brand_id"]?>' target="_blank"> <?=$row["brand_name"]?>
| </a> <?
} //====================================== }
$i++;
}
//PageLine($nr->rows,$lines,$linkurl,$p,1);
}
?>
</td>
</tr>
</table>
</div>看上面的代码有没有错?