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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测