Multiple-column display of individual database fields in PHP (single segment paging, lateral output) _php instance

Source: Internet
Author: User

Today in the project, encountered a problem is to read out from the database of the same field branch of the display, that is, each row shows 12 columns, based on the total number of records to control the number of cyclic lines. If it is a lot of fields to achieve, a loop to do, if it is a field loop then more trouble, the need to use a number of loops as well as incremental variables, online also have a lot of phper encounter similar problems, today's small set to share their solutions.

For the same field loop multiline and control column display number, the principle is to use the limit limit read the first loop, and then take the first time to read out the number of records added to the number of columns to display each row. The following is attached directly to the code:

First round code:

<tr>
<?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)) {
?> 
<td>
<input type= checkbox ' name= ' Menuemployname "Id=" Menuemployname "value=" <?php echo $inf [' Ei_employeename ']?> ']/><?php echo $inf [' Ei_employeename ']? >
</td>
<?php}?>
</tr>
Loop code after:
<?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;
? > 
<tr>
<?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)) {
?> 
<td>
<input type= checkbox ' Name= ' Menuemployname "id=" Menuemployname "value=" <?php echo $inf [' Ei_employeename ']?> ']/><?php echo $inf [' EI_ EmployeeName ']?>
</td>
<?php}?>
</tr>
<?php}?>

Of course there is a more direct method, that is, the first cycle of multiple loops, only to change the first parameter of limit. Hope to be helpful for beginners phper.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.