在多列中显示数据 [英] display data in multiple columns

查看:145
本文介绍了在多列中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从一个mySQL表中构建一个有四列的表。
这里是我现在:

 <?php 

table>;
while($ row = mysql_fetch_array($ result,MYSQL_ASSOC))
{
< tr>;
< td>;
print(< p>< img id ='g1'src ='/ $ row [img]'width = 130 height = 130 onClick ='f1()'&
print(< p> Name:$ row [name]< br>);
< / td>;
< / tr>;
< / table>;
}


?>

输出将是一个列表,如下所示:



>



我需要将表格放在四列中,如下所示:



解决方法:这是可能的吗?方案

 <?php 
$ items_in_row = 4;
$ index = 0;
?>

< table>
< tr>

<?php
while($ row = mysql_fetch_array($ result,MYSQL_ASSOC)){
$ index ++; ?>
< td>
< p>
< img id ='g1'src ='/<?php echo $ row [img];?" width = 130 height = 130 onClick ='f1()'&
< / p>
< p>名称:<?php echo $ row ['name'];?>< / p>
< br>
< / td>
<?php if($ index%$ items_in_row == 0){?>
< / tr>
< tr>
<?php}
}?>
< / tr>
< / table>

已编辑


Hi I need to build a table with four columns from a mySQL table. Here is what i have now:

 <?php

 "<table>";
     while ( $row = mysql_fetch_array( $result , MYSQL_ASSOC) )
     {
         "<tr>";
         "<td>";         
           print("<p><img id='g1' src='/$row[img]' width=130 height=130 onClick='f1()'>" );  
           print( "<p> Name: $row[name] <br>");    
          "</td>";
      "</tr>";
        "</table>";
           }


  ?>

the output will be one column table like this:

I need the table to be in four columns like this:

Is this possible if it is how do I do that?

解决方案

<?php
$items_in_row = 4 ;
$index = 0 ;
?>

<table>
  <tr>

<?php
while ($row = mysql_fetch_array( $result , MYSQL_ASSOC)){ 
  $index++ ; ?>
  <td>       
    <p>
      <img id='g1' src='/<?php echo $row["img"] ;?>' width=130 height=130 onClick='f1()'>" ; 
    </p>
    <p> Name: <?php echo $row['name'] ; ?> </p>
    <br>
  </td>
<?php if ($index%$items_in_row == 0){ ?>
  </tr>
  <tr>
<?php }
} ?>
</tr>
</table>

Edited

这篇关于在多列中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆