0

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
  • 2
    array() is not a function (even though the syntax looks like one). And you cannot magically pass arguments to that function and expect them to do something -- it was not designed for that. Commented Jul 26, 2013 at 8:45

1 Answer 1

1

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");
}
Sign up to request clarification or add additional context in comments.

14 Comments

Unfortunately that (not taking arguments) in itself is not a problem in PHP as per default all functions support variable arguments - see php.net/manual/en/function.func-get-args.php
Yes, but if the function doesn't look for any arguments, it's not exactly going to do anything no matter what/how many arguments you pass it
Thanks Smokey, but I'm getting this error now using your code: (database) line N/A: Unknown column 'collection.id' in 'where clause'<br/><br/>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 AND collection.id = 5 order by collection.ref desc
@user2621921 You mentioned the use of an id - if it's not in the collection table, change collection.id to resource.id or whatever table your ID of 5 refers to
Ok brill this worked collection.ref :-) However now I want to do the opposite in this function and eclude the id of 5: 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"); }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.