Home > php教程 > php手册 > body text

php中单个数据库字段多列显示(单字段分页、横向输出),多列分页

WBOY
Release: 2016-06-13 09:28:20
Original
820 people have browsed it

php中单个数据库字段多列显示(单字段分页、横向输出),多列分页

今天在做项目时,遇到个问题就是把从数据库读出来的同一字段分行分列显示,就是每行显示12列,根据总记录数控制循环行数。如果是多字段很好实现,一个循环搞定,如果是一个字段循环那么就比较麻烦了,需要同时用到多个循环还有递增变量,网上也有很多Phper遇到相似的问题,今天小编把自己的解决方案分享大家。

对于同一字段循环多行和控制列显示个数,实现原理就是先用Limit限制读出第一次循环,然后拿第一次循环读出的记录数加上要每行显示的列数。下面直接附上代码:

第一次循环代码:

<tr>
<&#63;php
$rer=mysql_query(“select EI_EmployeeId,EI_EmployeeName from employeeinfo order by EI_EmployeeId asc limit 0,10″);
while($inf=mysql_fetch_array($rer)){
&#63;> 
<td>
<input type=”checkbox” name=”menuemployname” id=”menuemployname” value=”<&#63;php echo $inf['EI_EmployeeName']&#63;>”/><&#63;php echo $inf['EI_EmployeeName']&#63;>
</td>
<&#63;php }&#63;>
</tr>
Copy after login

之后循环代码:

<&#63;php
$rer=mysql_query(“select EI_EmployeeId,EI_EmployeeName from employeeinfo order by EI_EmployeeId asc”);
$num=mysql_num_rows($rer);
$i=0;$j=10;
$count=ceil($num/$j);
for($k=0;$k<$count;$k++){
$i=$i+$j;
&#63;> 
<tr>
<&#63;php
$rer=mysql_query(“select EI_EmployeeId,EI_EmployeeName from employeeinfo order by EI_EmployeeId asc limit $i,$j”);
while($inf=mysql_fetch_array($rer)){
&#63;> 
<td>
<input type=”checkbox” name=”menuemployname” id=”menuemployname” value=”<&#63;php echo $inf['EI_EmployeeName']&#63;>”/><&#63;php echo $inf['EI_EmployeeName']&#63;>
</td>
<&#63;php }&#63;>
</tr>
<&#63;php }&#63;>
Copy after login

当然还有更直接的方法,就是多次循环第一次循环,只需要改动Limit的第一个参数即可。希望对于初学者phper有所帮助。

php 的数据库字段是日期时间类型,php 分页显示的时连时间都有,太长了,怎只显示日期没显示时间

我建议你存的时候存用time()函数的到的秒,数据表字段类型弄成int(10)就可以,输出的时候可以直接用date('Y-m-d',db['time'])格式化输出了!
 

php输出mysql数据库中指定字段段内容

// 数据库连接部分省略

$q = mysql_query("select User,Tel from darkit.Users limit 10", $lnk);
while($rs = mysql_fetch_assoc($q)){
echo $rs['User'], " : ", $rs['Tel'], "
";
}

///////
 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template