dongying3744 2009-08-26 01:07
浏览 37
已采纳

从PHP循环输出正确的HTML的最佳方法是什么?

I have a problem, I have a HTML problem, I don't know if i'm using the best method, so here is my problem: Everthing is ok:http://screencast.com/t/uJmffaxE
If i have more space, here are starting the problems: http://screencast.com/t/1z1GRhOLK
Here is my code:

<div id="wrap-categories" class="clearfix">
<?php if($this->categories !== false): ?>
    <ul>
    <?php foreach($this->categories as $category):?>
        <li>
            <strong><?=$category['name']?></strong><br />
        <?php if($this->artistsHelper($category['id']) !== false): ?>
            <?php foreach($this->artistsHelper($category['id']) as $artist): ?>
                <p><?=$artist['name']?></p>
            <?php endforeach; ?>    
        <?php endif; ?>
        </li>   
    <?php endforeach; ?>
    </ul>
<?php endif; ?>

And here is how the markup looks like, when is generated:

            <div id="wrap-categories" class="clearfix">

                                <ul>
                                        <li>
                        <strong>Dj's</strong><br />
                                                                                <p>Big artists</p>
                                                        <p>asddssdadsasda</p>
                                                        <p>Gigle bossu</p>

                                            </li>   
                                        <li>

                        <strong>Make up</strong><br />
                                                                                <p>Cool</p>

                                            </li>   
                                        <li>
                        <strong>Mamam</strong><br />
                                            </li>   
                                        <li>
                        <strong>Tata</strong><br />

                                            </li>   
                                        <li>
                        <strong>Dawaj</strong><br />
                                            </li>   
                                        <li>
                        <strong>Sexy</strong><br />
                                            </li>   
                                        <li>
                        <strong>Bitch</strong><br />

                                            </li>   
                                        <li>
                        <strong>Armin</strong><br />
                                            </li>   
                                        <li>
                        <strong>Lol</strong><br />
                                            </li>   
                                        <li>
                        <strong>Gogu</strong><br />

                                            </li>   
                                        <li>
                        <strong>Penal</strong><br />
                                            </li>   
                                        <li>
                        <strong>Asasin</strong><br />
                                            </li>   
                                    </ul>
                        </div>

The css

#wrap-categories ul li{
float:left;
margin-right:10px;
}

Any help please?!

  • 写回答

4条回答 默认 最新

  • drt12345678 2009-08-26 18:34
    关注
     <?php $x = 1?>         
     <?php if($this->categories !== false): ?>
        <?php foreach($this->categories as $category):?>
            <div class="column" <?=($x == 6) ? "style=\"clear:left\"" : false;?>>
                <ul>
                    <li class="category"><?=$category['name']?></li> <!-- header data... -->
                <?php if($this->artistsHelper($category['id']) !== false): ?>
                        <?php foreach($this->artistsHelper($category['id']) as $artist): ?>
                                <li><?=$artist['name']?></li> <!-- no class info here because its just text -->
                        <?php endforeach; ?>    
                <?php endif; ?>
                </ul>
                <?php ($x == 6) ? $x = 1 : $x++;?>
             </div>   
        <?php endforeach; ?>
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?