0

my aim is to pull data from mysql and print it in html table. asumming that 1,2,3...8 are the data

<table style="width: 100%">
 <tr>
 <td>1</td>
 <td>2</td>
 <td>3</td>
 <td>4</td>
</tr>
 <tr>
 <td>5</td>
 <td>6</td>
 <td>7</td>
 <td>8</td>
 </tr>
</table>

this is the code i have so far but this will only print out the column but no the row. plz help. thank you

<table style="width: 100%; color:aqua">
<?php               
$showFoto = getFoto();
echo '<tr>';
foreach($showFoto as $Foto){
echo '<td class="afs"><img alt="" src="img/'.$Foto['img'].'.'.$Foto['ext'].'"><br>'.$Foto['about'].'</td>';
}
echo '</tr>';
?>
</table>
3
  • You need to wrap another loop around your <tr> just as you did with your <td>. Commented Feb 17, 2012 at 20:57
  • php.net/manual/fr/function.print-r.php if you go down there's a print_nice function. i used it for similar situations. Commented Feb 17, 2012 at 20:57
  • Your echo '<tr>'; and echo '</tr>'; are outside of any loop structure. Commented Feb 17, 2012 at 20:58

1 Answer 1

1

TRY

 <table width ="100%" style="color:aqua" cellpadding="2" cellspacing="2">
    <tr>
 <?php               
    $showFoto = getFoto();
    $i=0;
    foreach($showFoto as $Foto){
      ++$i;
      echo ($i%4==0) ? '</tr><tr>' :'';
      echo '<td class="afs">
            <img alt="" src="img/'.$Foto['img'].'.'.$Foto['ext'].'">'.$Foto['about'].
           '</td>';         
    }
    ?>
    </tr>
 </table>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.