dongyange1101 2014-02-21 10:23
浏览 51
已采纳

使用PHP显示带有图像的表

Here's my code :

<?php
$items = array();
$images = node_files(request('nid')) ; 
$gallery_cover = db_fetch_row("node_meta","nid='".request('nid')."' AND name='gallery_image'");


foreach ($images as $key => $value)
{
$items[$key]['weight'] = $value['fid'].'_'.$value['weight'] ;
$items[$key]['image'] = '<a href="'.image_url($value['uri']).'" data-lightbox="gallery-image_'.$value['fid'].'">'.image_load($value['uri'],array("class"=>"img-thumbnail","thumbs"=>"small")).'</a>' ;
$items[$key]['title'] = '<span id="title_file_'.$value['fid'].'">'.$value['title'].'</span>' ;

$cover = "<a href='javascript:void(0);' onclick='javascript:gallery_cover(\"".$value['fid']."\"); return false;' id='gallery_cover_".$value['fid']."' data-toggle='tooltip' class='data-tooltip' data-placement='top' data-original-title='Top' id='tooltip1'><span class='btn btn-default btn-sm glyphicon glyphicon-eye-".(isset($gallery_cover['value']) && $gallery_cover['value']==$value['fid']?'open':'close')."'></span></a>" ; 
$edit = "<a href='javascript:void(0);' onclick='javascript:update_file(\"".$value['fid']."\"); return false;' data-toggle='tooltip' class='data-tooltip' data-placement='top' data-original-title='Modifier' id='tooltip1'>".IMG_EDIT."</a>" ; 
$delete = "<a href='javascript:void(0);' onclick='javascript:delete_added_image(\"".$value['fid'].'_'.$value['weight']."\"); return false;' data-toggle='tooltip' class='data-tooltip' data-placement='top' data-original-title='Supprimer' id='tooltip1'>".IMG_DELETE."</a>" ; 

$items[$key]['actions'] = $cover." ".$edit." ".$delete ;    
}
foreach($images as $key => $value)
{
if ($key % 4 == 0)
echo "<div class=\"row\">" ; 
    echo "<div class=\"col-md-3\">" ;
echo "<div class='thumbnail'><img src=".image_url($value['uri'])"/>
    <div class='caption'>
        <h4>".$value['title']."</h4> // <--- HERE THE ERROR SHOW
        <p>$cover $edit $delete</p>
    </div></div>" ;
echo "</div>" ;
}
?>

I'm trying to dsiplay 4 images in row with the title and the actions $cover $edit $delete and this code generate errors. Where did I go wrong? this is the error :

syntax error, unexpected '"/> ' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

Thanks

  • 写回答

1条回答 默认 最新

  • duanliao3826 2014-02-21 10:25
    关注

    You:

    • forgot to close the bracket at the very end
    • forgot to add a dot in the string concatenation

    --

    foreach($images as $key => $value)
    {
        if ($key % 4 == 0)
        echo "<div class=\"row\">" ; 
        echo "<div class=\"col-md-3\">" ;
        // added a dot in the line below (almost at the end)
        echo "<div class='thumbnail'><img src=".image_url($value['uri']) . "/>
            <div class='caption'>
            <h4>".$value['title']."</h4>
            <p>$cover $edit $delete</p>
            </div></div>" ;
        echo "</div>" ;
    } // <--- HERE
    ?>
    

    For the future, I advice using some (any) IDE, e.g. NetBeans (my favourite) or Eclipse. They're free open source very powerfull tools. If you can afford you can try with PHPStorm which is, IMHO, the best of those three but not free :)

    And also for future sakes, I would advice some other style for HTML outputting in PHP. If you're doing echo directly in the loop, why not doing it outside the PHP? Like this:

    foreach($images as $key => $value)
    {
        if ($key % 4 == 0)
        echo "<div class=\"row\">" ;
    
        // let's close the PHP block here
        ?>
        <div class="col-md-3">
            <div class="thumbnail">
                <img src="<?= image_url($value['uri']); ?>" />
                <div class="caption">
                    <h4><?= $value['title']; ?></h4>
                    <p><?= $cover . ' ' . $edit . ' ' . $delete; ?></p>
                </div>
            </div>
        </div>
        <? // let's open PHP block again
    }
    

    This method has lots of advantages:

    • HTML markup is more clear to read (helps you avoid syntax errors)
    • IDE will format the markup with the tabs
    • IDE will color the HTML syntax
    • if you're using CSS classes in the markup, IDE will link them to CSS files, it means it will auto-complete suggested classes when you're editing a CSS file
    • if any HTML syntax errors occur, IDE will show them
    • you can always inject PHP in the markup thanks to <?=. It opens the PHP stream and does the echo. It's simply the same as <? echo.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题