小白,请指点以下程序怎么不是循环输出的,而且输出的中文还是乱码
<?$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

AI Hentai Generator
Generate AI Hentai for free.

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
