drbxr86044 2013-07-26 08:41
浏览 41
已采纳

PHP函数和数组语法问题

I'm really struggling with something and wondered if anyone could spare a few moments to have a look at this code block.

The original line looked like this: $home_collectionsx=get_home_page_promoted_collections();

This brought back all the promoted to homepage items and displayed them on the homepage. I however simply want to pull 1 item in using the same code and an array function, the id is 5 for this purpose so I thought adding =array(5) or (array (5)) would work - but it doesn't.

I'm hoping it's something simple, or something that I have missed or not written correctly.

<?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
?>

This is the function to the DB itself that the above code is connecting to…

function get_home_page_promoted_collections()
{
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 order by collection.ref desc");
}

Any help would be hugely appreciated :-)

Many many thanks Rich

  • 写回答

1条回答 默认 最新

  • doudang9147 2013-07-26 08:43
    关注

    That function doesn't take a parameter: get_home_page_promoted_collections()

    You want something like:

    $home_collectionsx=get_home_page_promoted_collections(5);
    

    And:

    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");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能