我有这个用PHP制作的代码,我用<<<HTML
使用变量$ style集成了一个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>";
答案 0 :(得分:0)
将<?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;
}
?>
移出foreach语句。
如果将它放在foreach中,它将显示与foreach循环一样多的数据。
我不知道为什么你习惯了许多foreach。 只是另一个建议,编写代码以便更好地调试。您还需要了解如何为元素放置容器/包装器。 请参阅代码更新。
{{1}}