Home > Backend Development > PHP Tutorial > A revised version of the implementation code for php output table

A revised version of the implementation code for php output table

WBOY
Release: 2016-07-29 08:43:59
Original
994 people have browsed it

Many codes on the Internet are wrong, and this site has specially corrected them.

Copy the code The code is as follows:




Two rows and five columns, a total of 10 data


< body>


$num = 5; //The number of columns currently displayed in each row
$k = 1; //Initialization
while($k<=10)
{
if($k % $num == 0){
if($k==10){
echo ''."rn";
}else{
echo ''."rn";
}
}
else {
echo ''."rn";
}
$k+=1; //Add
}
?>
'.$k.'
'.$k.'
'.$k.'




The following is read from the database:

Copy the code The code is as follows:


$sql = "select * from table ";
$query = mysql_query($sql);
$num = mysql_num_rows($query);
for($i=0;$i <$num;$i++) {
$result = mysql_fetch_array($query);
if($i%3==0){
$str.= " ";
}
$str.= " ".$result[ "title " ]. " ";
if(($i+1)%$num==0) {
$str.= " ";
}
}
?>
< ;table border=0>
echo $str;
?>

The above introduces the revised version of the implementation code of the PHP output table, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template