php - Fixed Table Size -
foreach($model $person) { if($n % 3 == 0) $html = $html .'<tr>'; $html = $html . '<td width="95px" style="text-align:center">'. student photo.'</td>'; $html = $html . '<td width="80px">'.name.'</td>'; if(($n+1) % 3 == 0) $html = $html . '</tr>'; $n++; } $html = $html . '</table>'; echo $html; i want display 3 sets of student pic + name in each row. display nicely how want be.however, when display 1 or 2 records,the data not fixed. * want same size/position 3sets data
i can't tell styles may have applied table, think going on: cells changing position because when have 1 or 2 entries, table 2 or 4 cells wide, unlike when have 3+ entries, table 6 cells wide.
since you're using percentage-based widths name cells, you'll weird effects name cells try compute how wide should be. try using pixel-widths name cells, padding table blank cell, or setting width of table?
what see going on:
<h3> 3 cells </h3> <table> <tr> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> </tr> </table> <br/><br/> <h3> 2 cells </h3> <table> <tr> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> </tr> </table> the simplest solution problem insert pairs of blank cells matching width of cells there if have full row of pictures.
<h3> 3 cells </h3> <table> <tr> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> </tr> </table> <br/><br/> <h3> 2 cells </h3> <table> <tr> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px"></td><td width="23%"></td> <!-- see pair of spacers --> </tr> </table> <br/><br/> <h3> 1 cell </h3> <table> <tr> <td width="95px" style="text-align:center">photo</td><td width="23%">first , last name</td> <td width="95px"></td><td width="23%"></td> <!-- see pair of spacers --> <td width="95px"></td><td width="23%"></td> <!-- see pair of spacers --> </tr> </table> assuming "n" scoped outside of loop, bit of code similar this: (i don't have php handy check it)
foreach($model $person) { if($n % 3 == 0) $html = $html .'<tr>'; $html = $html . '<td width="95px" style="text-align:center">'. student photo.'</td>'; $html = $html . '<td width="23%">'.name.'</td>'; if(($n+1) % 3 == 0) $html = $html . '</tr>'; $n++; } $temp_n = n while($temp_n % 3 !=0){ $html = $html . '<td width="95px" ></td><td width="23%"></td>'; if(($temp_n+1) % 3 == 0) $html = $html . '</tr>'; $temp_n++; } $html = $html . '</table>'; echo $html; a prettier solution:
.fixedtable{ width:100%} .profile{ width: 33%; background-color:#eee; } .profile .photo, .profile .info{ display:block; float:left; } .profile .info {padding:4px} .clear{clear:both} <h3> 3 cells </h3> <table class="fixedtable" cols="3"> <tr> <td class="profile"> <img src="http://placehold.it/95x96" class="photo"><div class="info">first , last name</div><span class="clear"></span> </td> <td class="profile"> <img src="http://placehold.it/95x96" class="photo"><div class="info">first , last name<br/> more information</div><span class="clear"></span> </td> <td class="profile"> <img src="http://placehold.it/95x96" class="photo"><div class="info">first , last name</div><span class="clear"></span> </td> </tr> </table> <br/><br/> <h3> 2 cells </h3> <table class="fixedtable" cols="3"> <tr> <td class="profile"> <img src="http://placehold.it/95x96" class="photo"><div class="info">first , last name</div><span class="clear"></span> </td> <td class="profile"> <img src="http://placehold.it/95x96" class="photo"><div class="info">first , last name</div><span class="clear"></span> </td> <td></td> </table>
Comments
Post a Comment