Get latest product review (need some help)

hey guys,



can someone point me in the right direct to display the latest product reviews from the discussion addon in a tpl file?



i have the addon setup and the block added with some test test coming through but i need to build the function in func.php to get the latest product reviews and then pass it to the tpl to display.



Urgently need to get this done so if someone could help out would be awesome of you!



I started with this in func.php but dont think im doing it right as took bits from func.php on the discussion addon as its the same functions i want to do but getting the latest rather than showing on the product page:



func.php


```php


if ( !defined('AREA') ) { die('Access denied'); }

function fn_display_reviews_get_discussion($object_id, $object_type)
{
static $cache = array();

$_cache_key = $object_id . '_' . $object_type;

if (empty($cache[$_cache_key])) {
$cache[$_cache_key] = db_get_row(
"SELECT thread_id, type, object_type FROM ?:discussion WHERE object_id = ?i AND object_type = ?s ?p"
);
}

return !empty($cache[$_cache_key]) ? $cache[$_cache_key] : false;
}

function fn_display_reviews_posts($thread_id = 0,$random = 'N')
{
$reviews_data = db_get_field("SELECT thread_id, type, object_type, object_id FROM ?:discussion ?p");

if ($reviews_data['type'] == 'D') {
return false;
}
$join = $fields = '';

if ($reviews_data['type'] == 'C' || $reviews_data['type'] == 'B') {
$join .= " LEFT JOIN ?:discussion_messages ON ?:discussion_messages.post_id = ?:discussion_posts.post_id ";
$fields .= ", ?:discussion_messages.message";
}

if ($reviews_data['type'] == 'R' || $reviews_data['type'] == 'B') {
$join .= " LEFT JOIN ?:discussion_rating ON ?:discussion_rating.post_id = ?:discussion_posts.post_id ";
$fields .= ", ?:discussion_rating.rating_value";
}

$order_by = $random == 'N' ? '?:discussion_posts.timestamp DESC' : 'RAND()';

$limit = "LIMIT 1";

return db_get_array(
"SELECT ?:discussion_posts.* $fields FROM ?:discussion_posts $join "
. "ORDER BY ?p $limit",
$order_by
);
}

?>

```

tpl file:


```php

{** block-description:display_reviews_homepage **}

{assign var=“discussion” value=fn_display_reviews_get_discussion:$object_type|fn_html_escape}



{if $discussion.object_type == 'E'}

{assign var=“posts” value=0|fn_display_reviews_posts}

{else}

{assign var=“posts” value=$discussion.thread_id|fn_display_reviews_posts}

{/if}



{if $posts}

{foreach from=$posts item=post}



{$post.name|escape}
{$post.timestamp|date_format:"`$settings.Appearance.date_format`, `$settings.Appearance.time_format`"}
{if $discussion.type == "R" || $discussion.type == "B"}


{include file="addons/discussion/views/discussion/components/stars.tpl" stars=$post.rating_value|fn_get_discussion_rating}

{/if}


{if $discussion.type == "C" || $discussion.type == "B"}

{$post.message|escape|nl2br}

{/if}


{/foreach}
{else}

  • No data found


{/if}
```

this is an updated version but i get error_occured with this

Im just stuck on this part, but if someone can help me get the data back to the tpl i will give te addon to them for free after im done which will be a full wroking addon with many extra settings and functions!

Ideally i need to do the following:

database tables:

cscart_discussion
Structurecscart_discussion_messages
Structurecscart_discussion_posts
Structurecscart_discussion_rating

get data from those tables and link together, looking at them i need:

thread_id (review ID)
object_id (Product ID)
object_type
type

from

cscart_discussion

so can then get the message, rating and other data from the other tables - the object_id is the product id so guess we need this so can make a link to the related product


Thanks in advance

Did you really double post?