PHP函数和数组语法问题

PHP函数和数组语法问题,php,arrays,function,syntax,Php,Arrays,Function,Syntax,我真的有点纠结,想知道是否有人能抽出一些时间来看看这个代码块 原始行如下所示: $home\u collectionsx=获取\u主页\u页面\u升级的\u收藏 这将带回所有升级到主页的项目,并将它们显示在主页上。但是,我只想使用相同的代码和数组函数拉入1项,为此,id为5,因此我认为添加=array5或array5会起作用,但实际上不行 我希望是一些简单的东西,或者是我遗漏了或者写得不正确的东西 <?php if(!hook("EditorsPick")): /* ----------

我真的有点纠结,想知道是否有人能抽出一些时间来看看这个代码块

原始行如下所示: $home\u collectionsx=获取\u主页\u页面\u升级的\u收藏

这将带回所有升级到主页的项目,并将它们显示在主页上。但是,我只想使用相同的代码和数组函数拉入1项,为此,id为5,因此我认为添加=array5或array5会起作用,但实际上不行

我希望是一些简单的东西,或者是我遗漏了或者写得不正确的东西

<?php 
if(!hook("EditorsPick")):
/* ------------ Collections promoted to the home page ------------------- */
$home_collectionsx=get_home_page_promoted_collections (array(5));
foreach ($home_collectionsx as $home_collectionx)
{
?>
<div class="EditorsPick">
<div class="HomePanel"><div class="HomePanelINtopEditors">
<div class="HomePanelINtopHeader">Editors Pick</div>
<div class="HomePanelINtopText">This is the editors pick of Asset Space...</div>
<div class="EditorsPicImage"><div style="padding-top:<?php echo floor((155-$home_collectionx["thumb_height"])/2) ?>px; margin-top: -24px; margin-bottom: -15px;">
<a href="<?php echo $baseurl_short?>pages/search.php?search=!collection<?php echo   $home_collectionx["ref"] ?>" onClick="return CentralSpaceLoad(this,true);"><img     class="ImageBorder" src="<?php echo   get_resource_path($home_collectionx["home_page_image"],false,"thm",false) ?>" width="<?php echo $home_collectionx["thumb_width"] ?>" height="<?php echo $home_collectionx["thumb_height"] ?>" /></div>
</div></div>
</div>
</div>
</div>
<?php
}
endif; # end hook homefeaturedcol
?>
任何帮助都将不胜感激:-

非常感谢
Rich

该函数不带参数:get\u home\u page\u promoted\u collections

你想要的是:

$home_collectionsx=get_home_page_promoted_collections(5);
以及:


数组不是函数,即使语法看起来像函数。您不能神奇地将参数传递给该函数并期望它们执行某些操作-它不是为此而设计的。不幸的是,在PHP中,不接受参数本身并不是问题,因为默认情况下,所有函数都支持变量参数-请参见“是”,但如果函数不查找任何参数,不管你传递了多少个参数,它都不会做任何事情Hanks Smokey,但是我现在用你的代码得到了这个错误:数据库行N/A:where子句中的未知列“collection.id”select collection.ref,collection.home\u page\u publish,collection.home\u page\u text,collection.home\u page\u image,resource.thumb\u height,resource.thumb\u集合的宽度在集合上左外部联接资源。home\u page\u image=resource.ref其中collection.public=1和collection.home\u page\u publish=1和collection.id=5按collection.ref排序desc@user2621921您提到了id的使用-如果它不在收集表中,将collection.id更改为resource.id或您的id为5的表引用此工作的collection.ref:-但是现在我想在此函数中执行相反的操作,并删除id为5的函数:获取\主页\提升\集合{return sql\u queryselect collection.ref,collection.home\u page\u publish,collection.home\u page\u text,collection.home\u page\u image,resource.thumb\u width from collection left outer join resource on collection.ref image=resource.ref其中collection.public=1和collection.home\u page\u publish=1按collection.ref desc;}排序
$home_collectionsx=get_home_page_promoted_collections(5);
function get_home_page_promoted_collections($id=null)
{
    $filterClause = '';
    if(!is_null($id))
    {
        //to only return this id
        $filterClause = ' AND collection.ref = '.intval($id);
        //to get all but that id
        $filterClause = ' AND collection.ref != '.intval($id);
    }
    return sql_query("SELECT collection.ref,collection.home_page_publish,collection.home_page_text,collection.home_page_image,resource.thumb_height,resource.thumb_width FROM collection LEFT OUTER JOIN resource on collection.home_page_image=resource.ref WHERE collection.public=1 AND collection.home_page_publish=1".$filterClause." ORDER BY collection.ref DESC");
}