Results 1 to 3 of 3

Thread: what am doing wrong ?

  1. #1
    Join Date
    Sep 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default what am doing wrong ?

    PHP Code:
    <? $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) % != 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 ?

  2. #2
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    your php code is untidy for eyesigns, can you make your code more confortable..? he he he
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?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: 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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •