时间:2021-07-01 10:21:17 帮助过:13人阅读
$db_host = 'localhost';$db_user = 'root';$db_password = 'root3306';$db_database = 'chuyu';$con = mysql_connect($db_host, $db_user, $db_password);mysql_query("set names 'gb2312'"); if(!$con){die('数据库连接失败: ' . mysql_error());}mysql_select_db($db_database);global $site;$site_data=mysql_query("select * from dh_member_control where id=1",$con);$site=mysql_fetch_array($site_data);$hot_vip_data=mysql_query("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12",$con);$hot_vip=mysql_fetch_array($hot_vip_data);$i=1;while ($hot_vip && $i<=12){if ($i % 6 == 0){$last=" class=\"last\"";}else{$last="";}$i++;?>
你的 $hot_vip=mysql_fetch_array($hot_vip_data); 在循环外,且只执行了一次
如果没有 $i<=12 的话 while 都死循环了
至于乱码因素很多,你先把循环问题解决了再说
$hot_vip= mysql_fetch_array($hot_vip_data);
$i=1;
while ($hot_vip && $i<=12)
红色部分需要方在while里执行。
乱码问题估计没有加
解决方法如下:
';$db_host = 'localhost';$db_user = 'root';$db_password = 'root3306';$db_database = 'chuyu';$con = mysql_connect($db_host, $db_user, $db_password);mysql_query("set names 'gb2312'"); if(!$con){die('数据库连接失败: ' . mysql_error());}mysql_select_db($db_database);global $site;$site_data=mysql_query("select * from dh_member_control where id=1",$con);$site=mysql_fetch_array($site_data); $hot_vip_data=mysql_query("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12",$con);#$hot_vip=mysql_fetch_array($hot_vip_data);$i=1;while ($hot_vip=mysql_fetch_array($hot_vip_data) && $i<=12){if ($i % 6 == 0){$last=" class=\"last\"";}else{$last="";}$i++;?>
谢谢两位
问题解决了,但是我有还有个小疑惑:
$hot_vip_data = mysql_query("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12",$con);
$hot_vip = mysql_fetch_array($hot_vip_data);
while ($hot_vip ){...}
和
$hot_vip_data = mysql_query("SELECT * FROM dh_member WHERE `mck`=1 AND `photo`<>'/images/nan.png' AND `photo`<>'/images/nv.png' ORDER BY `mpower` DESC,`cktime` DESC LIMIT 1,12",$con);
while ($hot_vip = mysql_fetch_array($hot_vip_data)){...}
是一样的么?
不一样!
$hot_vip = mysql_fetch_array($hot_vip_data); //取回一条记录
while ($hot_vip ){...} //如果 $hot_vip 不为空的话,将是死循环
while ($hot_vip = mysql_fetch_array($hot_vip_data)){...} //循环读取每一条记录,直到 $hot_vip 为空(读完了)
不一样!
$hot_vip = mysql_fetch_array($hot_vip_data); //取回一条记录
while ($hot_vip ){...} //如果 $hot_vip 不为空的话,将是死循环
while ($hot_vip = mysql_fetch_array($hot_vip_data)){...} //循环读取每一条记录,直到 $hot_vip 为空(读完了)