This article mainly introduces the multi-column display of a single database field in php and the display of different branches. It can also be called single-field paging and horizontal output. if you need it, refer to the following when you are working on a project today, the problem is that the branch of the same field read from the database is displayed separately, that is, 12 columns are displayed in each row, and the number of cyclic rows is controlled based on the total number of records. If multiple fields are well implemented, one loop is done. if it is a field loop, it is troublesome. multiple loops and incremental variables need to be used at the same time, there are also many similar problems on the Internet with Phper. today, I will share my solutions with you.
When multiple rows and control columns are cyclically displayed in the same field, the principle is to read the first loop by using Limit, and then add the number of records read in the first loop to the number of columns displayed in each row. The following code is directly attached:
Code for the first loop:
<?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)){?> ”/><?php echo $inf['EI_EmployeeName']?><?php }?>
Loop code later:
<?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;?> <?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)){?> ”/><?php echo $inf['EI_EmployeeName']?><?php }?><?php }?>
Of course, there is a more direct method, that is, the first loop of multiple cycles, you only need to change the first parameter of Limit. I hope it will be helpful for beginners.