Log in

View Full Version : what am doing wrong ?



taydu
02-11-2009, 08:55 AM
<? $arrModel = $db->get_class_model($arrGroup[$i]["group_id"]);?>
<? $x = 1; ?>

<? foreach($arrModel as $k1 => $v1): ?>
<? if($db->model_num_item($v1["model_id"]) > 0): ?>
<? $file_row = $db->file_to_download($v1["model_id"]); ?>
<? if($x == 1): ?><tr><? endif; ?>
<td width="25%" align="center" height="30px"><a style="font-size: 12px; font-weight: bold" href="?act=download&model_id=<?=$v1["model_id"];?>"><?=(getIcon($v1["model_id"], 'model'))?getIcon($v1["model_id"], 'model'):$v1["model_name"];?></a><br /><i style="font-size: 10px; font-weight: normal">(<?=gmdate("m/d/Y", $file_row["date"]);?>)</i></td>
<? if($x == 4): ?></tr><? endif; ?>
<? $x++; ?>
<? endif; ?>
<? endforeach; ?>
<? if(count($arrModel) % 4 != 0): ?></tr><? endif; ?>

what i wanted is from 1 - 4 it will display on 1st row, 5 - 8 on 2nd, 9 - 12 on 3rd ....

1 - 4 and 5 - 8 is fine but if i have 9 or more it doesn't go to the 3 row but it squeeze on second row and make everything offset.

how can i fixed it ?

smansakra
02-12-2009, 01:54 AM
your php code is untidy for eyesigns, can you make your code more confortable..? he he he

Twey
02-12-2009, 01:48 PM
<?php $models = $db->get_class_model($arrGroup[$i]["group_id"]); ?>

<table>
<tr>
<?php for ($i = 0; $v1 = $models[$i]; ++$i):
if($db->model_num_item($v1['model_id']) > 0):
$file_row = $db->file_to_download($v1['model_id']); ?>
<td width="25%" style="height: 2em; text-align: center;">
<a style="font-weight: bold;"
href="?act=download&model_id=<?php echo $v1['model_id']; ?>">
<?php echo ($v = getIcon($v1["model_id"], 'model')) ? $v : $v1['model_name']; ?>
</a>

<span style="font-weight: normal;">
(<?php echo gmdate('m/d/Y', $file_row['date']); ?>)
</span>
</td>

<?php if(!($x % 4)): ?>
</tr>
<tr>
<?php endif; ?>

<?php endif; endfor; ?>
</tr>
</table>Your HTML is worse than your PHP. Run it through the validator (http://www.w3.org/): make sure it validates as HTML 4.01 Strict. Stuff to note: presentational elements (<i>) and attributes (height, width) are deprecated; pixel sizes shouldn't be used; you probably want classes for these: all actual CSS should be in your stylesheet. In PHP: the short opening tags <? and <?= are deprecated; double quotes shouldn't be used when you only need single (double quotes are less efficient). Don't be afraid of putting more than one statement in a PHP block (but by all means code as you were where it makes sense). Ideally you should have a big PHP block at the top of your code where everything's set up (logic part) and then a few single-liners scattered throughout your HTML to control flow (display part). PHP and HTML don't always jibe well in terms of indentation, but make an effort for the sake of legibility. If you need a counter anyway, there's no point in using foreach.