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 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)