Get latest product review (need some help)

hey guys, i know this is not comeplete or might be wrong as im new to php / smarty and be asked to do this job.



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


<br />
<?php<br />
<br />
if ( !defined('AREA') ) { die('Access denied'); }<br />
<br />
function fn_display_reviews_get_discussion($object_id, $object_type)<br />
{<br />
	static $cache = array();<br />
<br />
	$_cache_key = $object_id . '_' . $object_type;<br />
<br />
	if (empty($cache[$_cache_key])) {<br />
		$cache[$_cache_key] = db_get_row(<br />
			"SELECT thread_id, type, object_type FROM ?:discussion WHERE object_id = ?i AND object_type = ?s ?p"<br />
		);<br />
	}<br />
<br />
	return !empty($cache[$_cache_key]) ? $cache[$_cache_key] : false;<br />
}<br />
<br />
function fn_display_reviews_posts($thread_id = 0,$random = 'N')<br />
{<br />
		$reviews_data = db_get_field("SELECT thread_id, type, object_type, object_id FROM ?:discussion ?p");<br />
		<br />
		if ($reviews_data['type'] == 'D') {<br />
			return false;<br />
		}<br />
		$join = $fields = '';<br />
<br />
		if ($reviews_data['type'] == 'C' || $reviews_data['type'] == 'B') {<br />
			$join .= " LEFT JOIN ?:discussion_messages ON ?:discussion_messages.post_id = ?:discussion_posts.post_id ";<br />
			$fields .= ", ?:discussion_messages.message";<br />
		}<br />
	<br />
		if ($reviews_data['type'] == 'R' || $reviews_data['type'] == 'B') {<br />
			$join .= " LEFT JOIN ?:discussion_rating ON ?:discussion_rating.post_id = ?:discussion_posts.post_id ";<br />
			$fields .= ", ?:discussion_rating.rating_value";<br />
		}<br />
		<br />
		$order_by = $random == 'N' ? '?:discussion_posts.timestamp DESC' : 'RAND()';<br />
<br />
		$limit = "LIMIT 1";<br />
		<br />
		return db_get_array(<br />
			"SELECT ?:discussion_posts.* $fields FROM ?:discussion_posts $join "<br />
			. "ORDER BY ?p $limit",<br />
			$order_by<br />
		);<br />
}<br />
<br />
?><br />

```<br />
tpl file:<br />
<br />
```php
<br />
{** block-description:display_reviews_homepage **}<br />
{assign var="discussion" value=fn_display_reviews_get_discussion:$object_type|fn_html_escape}<br />
<br />
{if $discussion.object_type == 'E'}<br />
	{assign var="posts" value=0|fn_display_reviews_posts}<br />
{else}<br />
	{assign var="posts" value=$discussion.thread_id|fn_display_reviews_posts}<br />
{/if}<br />
<br />
{if $posts}<br />
{foreach from=$posts item=post}<br />
<div class="posts{cycle values=", manage-post"}" id="post_{$post.post_id}"><br />
		<div class="post-arrow"></div><br />
		<span class="post-author">{$post.name|escape}</span><br />
		<span class="post-date">{$post.timestamp|date_format:"`$settings.Appearance.date_format`, `$settings.Appearance.time_format`"}</span><br />
		{if $discussion.type == "R" || $discussion.type == "B"}<br />
		<br />
		<div class="clearfix"><br />
			{include file="addons/discussion/views/discussion/components/stars.tpl" stars=$post.rating_value|fn_get_discussion_rating}<br />
		</div><br />
		{/if}<br />
		<br />
	<br />
	{if $discussion.type == "C" || $discussion.type == "B"}<p class="post-message">{$post.message|escape|nl2br}</p>{/if}<br />
	<br />
</div><br />
{/foreach}<br />
{else}<br />
  <ul><br />
	<li>No data found</li><br />
  </ul><br />
{/if}<br />

```<br />
<br />
this is an updated version but i get error_occured with this<br />
<br />
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!<br />
<br />
Ideally i need to do the following:<br />
<br />
database tables:<br />
<br />
cscart_discussion<br />
Structurecscart_discussion_messages<br />
Structurecscart_discussion_posts<br />
Structurecscart_discussion_rating<br />
<br />
get data from those tables and link together, looking at them i need:<br />
<br />
thread_id (review ID)<br />
object_id (Product ID)<br />
object_type<br />
type<br />
<br />
from<br />
<br />
cscart_discussion<br />
<br />
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<br />
<br />
<br />
Thanks in advance

Did you really double post?

[quote name='JesseLeeStringer' timestamp='1367108926' post='160847']

Did you really double post?

[/quote]



I placed in the wrong section, and could not see where to remove the previous post