2013-07-26 106 views
0

我真的很苦惱,想知道是否有人可以花一點時間看看這個代碼塊。PHP函數和數組語法問題

原有線路是這樣的: $home_collectionsx=get_home_page_promoted_collections();

這勾起了所有晉升爲主頁項目,並顯示他們在主頁上。然而,我只是想使用相同的代碼和數組函數來獲取1個項目,爲此目的,ID爲5,所以我認爲添加=array(5)(array (5))會起作用 - 但事實並非如此。

我希望這是簡單的東西,或者我錯過了或沒有正確書寫的東西。

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

這是函數的DB本身,上面的代碼被連接到...

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"); 
} 

任何幫助將非常感激:-)

很多很多的感謝 豐富

+2

'陣列()'是不是一個函數(即使語法看起來像一個)。你不能神奇地將參數傳遞給該功能,並期望他們做一些事情 - 它不是爲此而設計的。 – Jon

回答

1

該函數不帶參數:get_home_page_promoted_collections()

你想要的東西,如:

$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"); 
} 
+0

不幸的是,(不接受參數)本身並不是PHP中的問題,因爲默認情況下所有函數都支持可變參數 - 請參見http://www.php.net/manual/en/function.func-get-args.php – griffin

+0

是的,但如果函數沒有尋找任何參數,不管什麼/你通過了多少個參數,它都不會做任何事情 – SmokeyPHP

+0

謝謝Smokey,但我現在使用你的代碼得到這個錯誤: (數據庫)行N/A:'where子句'中的未知列'collection.id'

select從集合中選擇collection.ref,collection.home_page_publish,collection.home_page_text,collection.home_page_image,resource.thumb_height,resource.thumb_width left outer join資源on collection.home_page_image = resource.ref其中collection.public = 1和collection.home_page_publish = 1 AND collection.id = 5 order by collecti on.ref desc – richyp147