【问题标题】:PHP gallery integrating CSS集成 CSS 的 PHP 库
【发布时间】:2015-07-28 11:19:21
【问题描述】:

我用 PHP 编写了这段代码,我使用变量 $style 集成了 <<<HTML 的 css 代码,样式在画廊的图像后面显示了 3 次,我怀疑它显示了 3 次,因为数量图片中,我的愿望是只出现一次。

我不明白它显示的图像数量? !

<?php
if( ! defined( 'CMSFUTURE' ) ) {
    die( "Hacking attempt!" );
}
$style = <<<HTML
<style>
.gallerypro{padding:5px 5px 0 5px;height: 120px; width: 543px; background-color: rgb(220,220,220); border:1px solid grey; box-shadow: 7px 8px 20px -5px rgba(0,0,0,0.47);}
</style>
HTML;
$distr_charset = "utf-8";
$self_id ='';
$homeUrl = $config['http_home_url'];
$rootPath = $_SERVER['DOCUMENT_ROOT'];
$fullpath = $rootPath."/uploads/jmgallery/";
include ('engine/api/api.class.php');
if($dle_module == "showfull") {
$id = $_GET['newsid'];
$getCg = $dle_api->load_table($table="dle_jmgallery", $fields="id", $where="id > 0", $multirow="false", $start="0", $limit="0", $sort="", $sort_order="");
$having = FALSE;
  foreach($getCg as $g){
    if($g['id'] == $id){$having = TRUE;}
  }
if($having == TRUE){
$getGal = $dle_api->load_table($table="dle_jmgallery", $fields="*", $where="id > 0", $multirow="true", $start="0", $limit="0", $sort="", $sort_order="");
  foreach($getGal as $carousel){
      $sizeW = $carousel['sizew'];
      $sizeH = $carousel['sizeh'];
      $dist = $carousel['distance']; 
      $self_id = $carousel['id'];    
      if($self_id == $id){
        $mask = "*.jpg";
        $idN = $fullpath.$id."/";
        $mask = $idN.$mask;
        if($sizeH == "0"){$sizeH = $sizeW; }
        foreach (glob($mask) as $filename) {
          $fileRname = substr($filename, -14);
          $picSizeW = $sizeW * 2;
          $img = "<img src='/uploads/jmgallery/$id/$fileRname' width='".$picSizeW."px' />";
          $galery .= "$style<div class='gallerypro'><a style='overflow:hidden; display:block; float:left; margin:".$dist."px 0 0 ".$dist."px; width:".$sizeW."px; height:".$sizeH."px;'  href='".$homeUrl."uploads/jmgallery/$id/$fileRname' onclick='return hs.expand(this)'>$img</a>"; } $xJ ="Computer repair"; $xJ = iconv("UTF-8", "UTF-8", $xJ); $galery .="<a href='$sitename' style='display:none; '>$xJ</a></div>";
          echo $galery."<br clear='left' />";
      }
    }
  }
  $having = FALSE;
}
?>

这是我得到的结果:

在图像的背景中看到了吗?该样式来自上面声明的变量 $style ,并用于:

$galery .= "$style<div class='gallerypro'><a style='overflow:hidden; display:block; float:left; margin:".$dist."px 0 0 ".$dist."px; width:".$sizeW."px; height:".$sizeH."px;'  href='".$homeUrl."uploads/jmgallery/$id/$fileRname' onclick='return hs.expand(this)'>$img</a>"; } $xJ ="Computer repair"; $xJ = iconv("UTF-8", "UTF-8", $xJ); $galery .="<a href='$sitename' style='display:none; '>$xJ</a></div>";

【问题讨论】:

  • 将 (echo $galery."
    ";) 移到 (foreach) 循环之外,因为它每次找到图像时都会回显图库
  • 感谢您的回答,Removing ,moving ,该行导致画廊根本不显示...

标签: php css integration


【解决方案1】:

$style 移出 foreach 语句。

如果你把它放在foreach里面,它会显示和foreach循环一样多。

我不知道你为什么习惯了很多 foreach。 只是另一个建议,编写代码以进行更好的调试。您还需要了解如何为您的元素放置容器/包装器。 查看代码的更新。

<?php
if( ! defined( 'CMSFUTURE' ) ) {
    die( "Hacking attempt!" );
}
$style = <<<HTML
<style>
.gallerypro{padding:5px 5px 0 5px;height: 120px; width: 543px; background-color: rgb(220,220,220); border:1px solid grey; box-shadow: 7px 8px 20px -5px rgba(0,0,0,0.47);}
</style>
HTML;
$distr_charset = "utf-8";
$self_id    ='';
$homeUrl    = $config['http_home_url'];
$rootPath   = $_SERVER['DOCUMENT_ROOT'];
$fullpath   = $rootPath."/uploads/jmgallery/";
include ('engine/api/api.class.php');
if($dle_module == "showfull") {
    $id = $_GET['newsid'];
    $getCg = $dle_api->load_table($table="dle_jmgallery", $fields="id", $where="id > 0", $multirow="false", $start="0", $limit="0", $sort="", $sort_order="");
    $having = FALSE;
    foreach($getCg as $g){
        if($g['id'] == $id){$having = TRUE;}
    }
    if($having == TRUE){
        $getGal = $dle_api->load_table($table="dle_jmgallery", $fields="*", $where="id > 0", $multirow="true", $start="0", $limit="0", $sort="", $sort_order="");
        $galerry    = $style."<div class='gallerypro'>";
        foreach($getGal as $carousel){
            $sizeW = $carousel['sizew'];
            $sizeH = $carousel['sizeh'];
            $dist = $carousel['distance']; 
            $self_id = $carousel['id'];    
            if($self_id == $id){
                $mask = "*.jpg";
                $idN = $fullpath.$id."/";
                $mask = $idN.$mask;
                if($sizeH == "0"){$sizeH = $sizeW; }
                foreach (glob($mask) as $filename) {
                    $fileRname  = substr($filename, -14);
                    $picSizeW   = $sizeW * 2;
                    $img        = "<img src='/uploads/jmgallery/$id/$fileRname' width='".$picSizeW."px' />";
                    $galery     .= "<a style='overflow:hidden; display:block; float:left; margin:".$dist."px 0 0 ".$dist."px; width:".$sizeW."px; height:".$sizeH."px;'  href='".$homeUrl."uploads/jmgallery/$id/$fileRname' onclick='return hs.expand(this)'>$img</a>";
                }
                $xJ         ="Computer repair";
                $xJ         = iconv("UTF-8", "UTF-8", $xJ);
                $galery     .="<a href='$sitename' style='display:none; '>$xJ</a>";
            }
        }
        $gallery    .= "</div>";
        echo $gallery;
    }
    $having = FALSE;
}
?>

【讨论】:

  • Hy Redy 我尝试这种方式是让我的画廊根本不显示,在更改代码后唯一显示的是'
    '
  • 是的,这可能导致。 br 给 1 个空行,clear: left 删除所有 float: left 对其他元素的影响。
  • 这不起作用,但你给我一个想法,这就是它起作用的原因:'echo $galery."$gogo
    ";加了 $gallery 其中 $gogo 是 $gogo = $style。 "
    ";
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-10
相关资源
最近更新 更多