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

Konsole
  • 3,447
  • 3
  • 29
  • 39
richyp147
  • 17
  • 5
  • 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. – Jon Jul 26 '13 at 08:45

1 Answers1

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");
}
MDEV
  • 10,730
  • 2
  • 33
  • 49
  • Unfortunately that (not taking arguments) in itself is not a problem in PHP as per default all functions support variable arguments - see http://www.php.net/manual/en/function.func-get-args.php – griffin Jul 26 '13 at 08:46
  • 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 – MDEV Jul 26 '13 at 09:24
  • Thanks Smokey, but I'm getting this error now using your code: (database) line N/A: Unknown column 'collection.id' in 'where clause'

    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
    – richyp147 Jul 26 '13 at 09:28
  • @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 – MDEV Jul 26 '13 at 09:30
  • 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"); } – richyp147 Jul 26 '13 at 09:56
  • No worries, glad to have helped. Just remember to accept the answer with the tick icon on the left of the answer – MDEV Jul 26 '13 at 10:05
  • I said perfect until I refreshed it, for some reason the Collections are being duplicated at the bottom of the page, If I move the new block below the existing collections it doesn't seem to do it – richyp147 Jul 26 '13 at 10:07
  • @user2621921 I'm not entirely sure I understand the issue - is the query returning duplicates of each row? – MDEV Jul 26 '13 at 10:10
  • It is if it's put in a certain place in the code, can I send you the page to look at somehow please? – richyp147 Jul 26 '13 at 10:11
  • If you put your code in http://phpfiddle.org/ or http://codepad.org/ and send me a link to the live site as well, sure – MDEV Jul 26 '13 at 10:13
  • I will have to give you a login to the live site as it's protected – richyp147 Jul 26 '13 at 10:14
  • This comment convo is getting a bit long! This is also a different problem - if you create a new question and accept this one, we'll go from there. Then you can post your new code without cluttering up this question – MDEV Jul 26 '13 at 10:18
  • @user2621921 You can send your login details through that if you wish, but if other people have a similar problem, it will be helpful to them if the issue can be discussed in a separate question on this site – MDEV Jul 26 '13 at 10:19
  • It's here: http://stackoverflow.com/questions/17879023/php-collection-code-duplication-upon-refresh-or-page-change – richyp147 Jul 26 '13 at 10:31