Display multiple columns of a single database field in php_PHP tutorial

WBOY
Release: 2016-07-13 10:21:46
Original
827 people have browsed it

Multi-column display of a single database field in php

This article mainly introduces the techniques of multi-column display and row and column display of a single database field in php, which can also be called single field Paging and horizontal output, friends who need it can refer to it

When I was working on a project today, I encountered a problem, which was to display the same field read from the database in rows and columns, that is, each row displays 12 columns, and the number of looping rows is controlled based on the total number of records. If it is multiple fields, it is easy to implement, and it can be done with one loop. If it is a field loop, it will be more troublesome. You need to use multiple loops and incremental variables at the same time. There are also many Phpers on the Internet who encounter similar problems. Today I will introduce my own Share the solution with everyone.

For looping multiple rows of the same field and controlling the number of columns displayed, the implementation principle is to first use Limit to limit the reading of the first loop, and then add the number of records read in the first loop to the number of columns to be displayed in each row. . Attached is the code directly below:

First loop code:

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

Loop code after
:

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

Of course there is a more direct method, which is to cycle through the first cycle multiple times. You only need to change the first parameter of Limit. Hope it helps for beginners in phper.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/852821.htmlTechArticleMulti-column display of a single database field in php This article mainly introduces the multi-column display and branching of a single database field in php Column display techniques, also known as single-field paging and horizontal output, require...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template