【发布时间】: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