我的会员列表出了点问题。它显示每个用户名,但我希望它只显示每行15。
代码:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="23%"><em><strong>Username</strong></em></td>
</tr>
<?
$sql = mysql_query("select * from usr_users");
while($m = mysql_fetch_array($sql))
{ ?>
<tr>
<td width="23%"><div style="float: left;" onMouseover="ddrivetip('<em><? echo("$m[username]");?></em> <br /> <b>Rank:</b> <? echo("$m[rankerslevel]");?><br /> <b>Bits:</b> <? echo("$m[credits]");?><br /> <b>Score:</b> <? echo("$m[points]");?><br /> <b>Mood:</b> <? echo("$m[usrstatus]");?><br /> <b>ID:</b> <? echo("$m[id]");?><br /> <b>Sex:</b> <? echo("$m[sexmalefemale]");?><br /> <b>Country:</b> <? echo("$m[countrywhere]");?><br />','white', 100)";
onMouseout="hideddrivetip()"><img src="/bolt.png" alt="member_icon"/> <a href="memb.php?user=<? echo("$m[username]");?>"><font color="<? echo("$m[usercolour]");?>"><? echo("$m[username]");?></font></a></td></div>
<? } ?>提前感谢!
发布于 2012-03-11 11:38:44
使用LIMIT子句。用法如下:
LIMIT [offset,] rows示例:
SELECT * from usr_users LIMIT 0, 10此查询将检索1-10行(从0到10)。
SELECT * from usr_users LIMIT 10, 10此查询将检索11-19行。
如果要获取具有特定ids行,请使用IN语句:
SELECT * from usr_users WHERE id IN (1,2,3)另请阅读:http://dev.mysql.com/doc/refman/5.0/en/select.html
如果您想了解如何进行分页,请查看此主题:http://www.codediesel.com/php/simple-pagination-in-php/
发布于 2012-03-11 11:56:38
最简单的解释是:
SELECT * FROM usr_users LIMIT 15发布于 2012-03-11 11:29:58
使用mysql限制
select * from usr_users order by createddate desc LIMIT 0, 15假设您有一个名为createddate的列,您在该列上执行order by。
这将为您提供最近创建的15个用户。
您可以获取记录总数,并将其除以“要显示的项目”,从而获得分页元素的数量。
http://www.dharshin.com/2007/09/paging-results-with-php-and-mysql-part.html
https://stackoverflow.com/questions/9652151
复制相似问题