<?
$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="<? echo $hot_vip["photo"]?>" /></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\" /></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里执行。
乱码问题估计没有加<meta>
解决方法如下:
<?
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="<? echo $hot_vip["photo"]?>" /></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\" /></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>
<? }?>