小白,请指点以下程序怎么不是循环输出的,而且输出的中文还是乱码
<?$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++;?><li <? echo $last;?> onclick="javascript:location.href='/display/?<? echo $hot_vip["id"]?>.html'"><div class="vpc"><img src="/static/imghw/default1.png" data-src="<? echo $hot_vip[" class="lazy" photo"]? alt="小白,请指点以下程序怎么不是循环输出的,而且输出的中文还是乱码" >" /></div><div class="vpn"><? if (strlen($hot_vip["unick"])>4){echo substr($hot_vip["unick"],1,4);}else{echo $hot_vip["unick"];}if ($hot_vip["mpower"]===2){ echo "<a href=\"/vip/\" title=\"初遇会员\"><img src=\"/images/v.png\" / alt="小白,请指点以下程序怎么不是循环输出的,而且输出的中文还是乱码" ></a>";} ?></div><div class="vpt"><? $timediff = strtotime (date("y-m-d")) - strtotime($hot_vip["sri"]) ;echo intval($timediff/(86400*365)) . "岁";echo $hot_vip["add"];?></div></li><? }?>
测试结果显示12条一样的记录,而且中文是乱码..
回复讨论(解决方案)
你的 $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里执行。
乱码问题估计没有加
解决方法如下:
<?echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';$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++;?><li <? echo $last;?> onclick="javascript:location.href='/display/?<? echo $hot_vip["id"]?>.html'"><div class="vpc"><img src="/static/imghw/default1.png" data-src="<? echo $hot_vip[" class="lazy" photo"]? alt="小白,请指点以下程序怎么不是循环输出的,而且输出的中文还是乱码" >" /></div><div class="vpn"><? if (strlen($hot_vip["unick"])>4){echo substr($hot_vip["unick"],1,4);}else{echo $hot_vip["unick"];}if ($hot_vip["mpower"]===2){ echo "<a href=\"/vip/\" title=\"初遇会员\"><img src=\"/images/v.png\" / alt="小白,请指点以下程序怎么不是循环输出的,而且输出的中文还是乱码" ></a>";} ?></div><div class="vpt"><? $timediff = strtotime (date("y-m-d")) - strtotime($hot_vip["sri"]) ;echo intval($timediff/(86400*365)) . "岁";echo $hot_vip["add"];?></div></li><? }?>
谢谢两位
问题解决了,但是我有还有个小疑惑:
$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 为空(读完了)
谢谢~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
