编辑php脚本è来输出一个表


Editing a php scripèt divs to output a table

嘿,伙计们,好吧,我正在制作一份客户每周通讯,我正在使用Joomla 2.5.19,并使用企业版的acymailing来发送它。因为outlook,我现在正在踢我的头,我使用的是Jreviews的一个模块,它在时事通讯中发布提交到网站的最新评论,除了outlook之外,一切都很好。

脚本的输出是一个2x2table,其中包含4个最新的评论。唯一的问题是outlook似乎讨厌我使用Div作为表格,并将2x2表格堆叠成一个垂直的混乱。

我想编辑的代码是:

">

<?php /* root element for the items */ ?>
<div class="jrModuleItems <?php echo $orientation . ' jrThumbnail'.ucfirst($tn_position); ?>">
    <?php /* new page starts here */
        $pages = array_chunk($reviews,$limit);
        $j=0;
        foreach($pages AS $page):
        ?>
    <div class="jr-results jrResults jrModuleContainer jrReviewsModule">
        <?php $i=0;
              while(!empty($page)):
                $i++; $j++; $review = array_shift($page); ?>
            <?php
            // Process link title
            $listing_title = ($listing_title_chars && mb_strlen($review['Listing']['title'])>$listing_title_chars) ? $Text->truncate($review['Listing']['title'],$listing_title_chars) : $review['Listing']['title'];
            $review_title = ($review_title_chars && mb_strlen($review['Review']['title'])>$review_title_chars) ? $Text->truncate($review['Review']['title'],$review_title_chars) : $review['Review']['title'];
            $link_title = str_replace('{listing_title}',$listing_title,$link_title_format);
            $link_title = str_replace('{review_title}',$review_title,$link_title);
            // Create the thumbnail
            $tn_show and $mainMediaThumb = $Media->thumb(Sanitize::getVar($review,'MainMedia'),array('listing'=>$review,'size'=>$tn_size,'mode'=>$tn_mode,'css_size'=>true));
            ?>
            <?php $lastItem = ($i == $columns) ? ' jrLastItem' : ''; ?>
            <div class="jrModuleItem<?php echo $lastItem; ?>" style="width: <?php echo $item_width; ?>%; padding-right: <?php echo $item_padding; ?>%;">
                <?php if($show_numbers):?><div class="jrModuleItemNumber"><?php echo $j;?>.</div><?php endif;?>
                <?php if($tn_show && $mainMediaThumb && $tn_position != 'bottom'):?>
                    <!-- Listing Thumbnail -->
                    <div class="jrModuleItemThumbnail">
                        <?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
                        <?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
                            // echo $Community->avatar($review);
                        ?>
                    </div>
                <?php endif;?>
                <div class="jrModuleItemContent">
                    <!-- Listing Title -->
                    <div class="jrModuleItemTitle">
                        <?php echo $Html->sefLink($link_title,$review['Listing']['url']);?>
                        <?php if(Sanitize::getString($review['Listing'],'tag')):?>
                            <span class="jrComponentLabel jrStatusLabel jrBlue">
                                <?php echo Sanitize::getString($review['Listing'],'tag');?>
                            </span>
                        <?php endif;?>
                    </div>
                    <!-- Rating -->
                    <?php if ( $review['Criteria']['state'] == 1 ):?>
                    <div class="jrOverallRatings">
                        <?php if($review['Review']['editor'] == 1):?>
                            <?php
                                $rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'editor');
                                $rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
                            ?>
                            <div class="jrOverallEditor" title="<?php  __t("Editor rating"); ?>">
                                <div class="jrRatingStars"><?php echo $rating_stars ?></div>
                                <span class="jrRatingValue"><?php echo $rating_value?></span>
                            </div>
                        <?php else:?>
                            <?php
                                $rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'user');
                                $rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
                            ?>
                            <div class="jrOverallUser" title="<?php  __t("User rating"); ?>">
                                <div class="jrRatingStars"><?php echo $rating_stars ?></div>
                                <span class="jrRatingValue"><?php echo $rating_value?></span>
                            </div>
                        <?php endif;?>
                    </div>
                    <?php endif;?>
                    <!-- Reviewer name -->
                    <div class="jrModuleItemReviewer">
                        <span class="reviewer"><?php __t("Reviewed by");?> <?php echo $Community->screenName($review);?></span>
                    </div>
                    <?php if($fields): ?>
                    <!-- Custom Fields -->
                    <div class="jrModuleFields">
                        <?php
                            foreach ($fields as $field):
                            $field = trim($field);
                            $field_value = $CustomFields->field($field,$review);
                        ?>
                        <?php if($field_value != ''):?>
                        <div class="jrModuleFieldDiv <?php echo lcfirst(Inflector::camelize($field)); ?>">
                            <span class="jrModuleFieldTitle"><?php echo $CustomFields->label($field, $review); ?>: </span>
                            <span class="jrModuleFieldValue"><?php echo $field_value; ?></span>
                        </div>
                        <?php endif;?>
                        <?php endforeach; ?>
                    </div>
                    <?php endif;?>

                    <?php if($show_comments && trim($review['Review']['comments'])!=''):?>
                    <!-- Review Comments -->
                    <div class="jrModuleItemInfo">
                        <?php
                            // Uncomment line below to show review title
                            // echo '<strong>' . $review['Review']['title'] . '</strong><br />';
                        ?>
                        <span class="comments">"<?php echo $Text->truncateWords($review['Review']['comments'],$comments_words,'...');?>"</span>
                    </div>
                    <?php endif;?>
                </div>
                <?php if($tn_show && $mainMediaThumb && $tn_position == 'bottom'):?>
                    <!-- Listing Thumbnail -->
                    <div class="jrModuleItemThumbnail">
                        <?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
                        <?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
                            // echo $Community->avatar($review);
                        ?>
                    </div>
                <?php endif;?>
            </div>
           <?php  /*end of row , start new row*/
                if(!empty($page) && ($i == $columns || $total == $j)):?>
                <div class="jrDivider"></div>
                <?php $i=0; endif;?>
        <?php endwhile;?>
    </div>
    <?php endforeach; /* new page ends here */?>
</div><?php /* end items root element */?>

有没有人有丝毫的想法,我怎么能把它变成一个循环输出一个表?

从A到B的最快路径是编辑附加的代码以呈现表格而不是堆叠div。

* EDIT *

你的评论的答案不是那么简单,把所有的'A'换成'B '。div是一个"自包含"的HTML元素,而table是一个具有语法规则的分组。

一个HTML表是这样构造的:

<table>
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
        </tr>
    </thead>        
    <tbody>
        <tr>
            <td>Row 1 - Column 1</td>
            <td>Row 1 - Column 2</td>
        </tr>
        <tr>
            <td>Row 2 - Column 1</td>
            <td>Row 2 - Column 2</td>
        </tr>
    </tbody>
</table>

代码中的foreach循环应该通过每次迭代创建一行。这意味着需要在循环代码之外呈现table、head和tbody标签。在循环中,每次迭代呈现一个新行,这需要行有开始/结束标记,每列有开始/结束标记。