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>
<?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.