Home >Backend Development >PHP Tutorial >Display a single database field in multiple columns in PHP (single field paging, horizontal output), multi-column paging_PHP tutorial

Display a single database field in multiple columns in PHP (single field paging, horizontal output), multi-column paging_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:05934browse

Multi-column display of a single database field in php (single field paging, horizontal output), multi-column paging

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>
<&#63;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)){
&#63;> 
<td>
<input type=”checkbox” name=”menuemployname” id=”menuemployname” value=”<&#63;php echo $inf['EI_EmployeeName']&#63;>”/><&#63;php echo $inf['EI_EmployeeName']&#63;>
</td>
<&#63;php }&#63;>
</tr>
Loop code after
:
<&#63;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;
&#63;> 
<tr>
<&#63;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)){
&#63;> 
<td>
<input type=”checkbox” name=”menuemployname” id=”menuemployname” value=”<&#63;php echo $inf['EI_EmployeeName']&#63;>”/><&#63;php echo $inf['EI_EmployeeName']&#63;>
</td>
<&#63;php }&#63;>
</tr>
<&#63;php }&#63;>

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.

The database field of PHP is of date and time type. PHP displays the time even in paging. It is too long. Why only the date is displayed but not the time?

I suggest you use the time() function to save the seconds. Just change the data table field type to int(10). When outputting, you can directly use date('Y-m-d',db[' time']) formatted output!

php outputs the content of the specified field segment 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'], "df250b2156c434f3390392d09b1c9563";
}

///////

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/851339.htmlTechArticleMulti-column display of a single database field in php (single field paging, horizontal output), multi-column paging I am working on a project today At that time, I encountered a problem that the same field read from the database was divided into rows...
Statement:
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