tags:

views:

38

answers:

2

I need to create a table in runtime by using php and html,the table should look like:-

image1      image2        image3
name1       name2         name3
---------------------------------
image4      image5       image6
name4       name5        name6

total 2 rows,each row containing 3 data,each data again containing 2 rows,one is a image and another is one name filed.

I have already tried like:

for($i=0;$i<2;$i++)
{
  ?> <tr>
   <? for($j=0;$j<3;$j++)
   {
   ?>
        <td>
                <table>
                    <tr> 
                         <td align="left" valign="top" >
                             <a href="#"> 
                              <img src="images/speak-pic.jpg" width="88" height="88" border="0" class="pic-bod" />
                              </a>
                          </td>
                    </tr>
                    <tr>
                           <td align="left" valign="top" >
                             <a href="#" class="link-ar">
                               <? echo $t["profile_name"]?>  
                             </a>
                           </td>
                    </tr>
                 </table> 
             </td>

      <?
   } 
   ?>
   </tr>
<? }
?>

but it is still not working

A: 

You should avoid the use of the short-form tag. Use <?php to start an inline PHP block.

On another note, it looks like your code there is missing a good chunk. Or you posted a strange excerpt.

Borealid
A: 

Although you are not really giving us enough code to help you, here some pointers to help you.

Firstly you are not describing very much what the problem is. The html looks solid, and the php looks boilerplate code.

  • However you might think it looks as a table, this is not really tabular data. Just a bunch of images with an attached link, grouped three per row. If you look it that way, it might be easier to format it with block elements (like div) and CSS. This allows for a floating design which doesn't need special cases when you have 7 elements and you need a row for only one item.

  • PHP has a lot of operators to make this kind of code more readable. If you look at http://fi.php.net/manual/en/control-structures.alternative-syntax.php you can for example find the following syntax:

    <?php foreach($dataarray as $datarow): ?>
        do_something($data);
    <?php endforeach; ?>
    

When you update your question with more information, I could expand this post with more help.

Peter Smit