In php, a single database field is displayed in multiple columns (single-field paging and horizontal output), and multiple columns are displayed in pagination _ PHP Tutorial

Source: Internet
Author: User
Tags php database
In php, multiple columns of a single database field are displayed (single-field paging and horizontal output), and multiple columns are displayed on multiple pages. In php, fields in a single database are displayed in multiple columns (single-field paging and horizontal output). when multiple columns are displayed in a project today, the problem is that the same field branch read from the database is divided into multiple columns of a single database field in php (single field paging and horizontal output), and multiple columns paging

Today, when I was working on a project, I encountered a problem: to display the branches of the same field read from the database, that is, to display 12 columns in each row, and to control the number of cyclic rows 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.


The php database field is of the date and time type. the connection time is displayed on the php page, which is too long. how can I only display the time when the date is not displayed?

I recommend that you store the time () function to the second when saving the data table, and set the field type to int (10, you can use date ('Y-m-D', db ['Time']) to format the output!

Php outputs the content of specified field segments in the mysql database

// The database connection part is omitted.

$ Q = mysql_query ("select User, Tel from darkit. Users limit 10", $ lnk );
While ($ rs = mysql_fetch_assoc ($ q )){
Echo $ rs ['user'], ":", $ rs ['tel'],"
";
}

///////

Partition (single-field paging and horizontal output). when multiple-column paging is performed for a project today, the problem is to split the same field read from the database into different branches...

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.