...

View Full Version : "limit_words" in script not working correctly



lamboe80
08-29-2007, 01:05 AM
I am using the phpMyDirectory script for a business directory site I am working on. Here's a link (http://findsoky.com/test) to my site.

On my homepage, I have a "recent reviews" box that shows the most recent reviews that have been left by site visitors. My php script uses limit_words to truncate reviews that are longer than a specified length. I can't get it to work correctly. Can somebody help?

Here's the php:

$sidebox_latestreviews = & new PMDTemplate(PMDROOT.TEMPLATE_PATH.'/blocks/sidebox_latestreviews.tpl','sidebox_latestreviews.tpl');
if(!($sidebox_latestreviews->is_cached())) {
$results = $db->GetAll("SELECT * FROM ".T_REVIEWS."
INNER JOIN ".T_LISTINGS." ON ".T_LISTINGS.".selector=".T_REVIEWS.".company
WHERE
date_expire > NOW() AND admin_approved=1 AND status='on'
GROUP BY ".T_LISTINGS.".selector
ORDER BY ".T_REVIEWS.".date DESC
LIMIT 8");

if(sizeof($results) > 0) {
foreach($results as $key=>$value) {
if (ifEnabled($results[$key]['membership'], "short_description") AND $value['review'] != "") {
$results[$key]['review'] = limit_words ($value['review'], '50' );
}
$results[$key]['link'] = getListingURL($value['selector'],$value['friendly_url']);
}
}
}
$sidebox_latestreviews->set('reviews',$results);
$sidebox_latestreviews->set('lang',$lang);
//$template_sidebox_latestreviews->set('date_type',$config['date_type']);

$template_sidebox_latestreviews = & new PMDTemplate(PMDROOT .'/template/' . $config['template'] . '/blocks/sidebox.tpl');
$template_sidebox_latestreviews->set('title',$lang['sidebox_latestreviews']);
$template_sidebox_latestreviews->set('content',$sidebox_latestreviews);
$template_sidebox_latestreviews->set('reviews',$sidebox_latestreviews);

This is the html used to display the table:


<table width="100%" cellpadding="0" cellspacing="0">
<?php foreach($reviews as $value) { ?>
<tr>
<td align="left" valign="top" width="100%">
<span class="text"><a href="<?php echo $value['link']; ?>" ><b><u><?php echo $value['firmname']; ?></b></u></a></span><br />
<span class="text_soft">By <?php echo $value['user']; ?></span>
</td>
</tr>
<tr>
<td align="left" valign="top" width="100%">
<span class="text"><?php echo $value['review']; echo '... <a href="' . $value['link'] . '#' . $value['id'] . '">read more</a></span>';?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<?php } ?>
</table>

Can somebody help? Is there another way that I can limit the length?

Mwnciau
08-29-2007, 01:20 AM
Where is this limit_words function?

You could use this:

function limit_words($text, $words){
return implode(' ', array_slice(explode(' ', $text), 0, $words));
}

lamboe80
08-29-2007, 01:22 AM
Where is this limit_words function?

You could use this:

function limit_words($text, $words){
return implode(' ', array_slice(explode(' ', $text), 0, $words));
}

Sorry... it's on about the 14th line:

$results[$key]['review'] = limit_words ($value['review'], '50' );

Mwnciau
08-29-2007, 01:39 AM
I meant where is the function defined?

lamboe80
08-29-2007, 02:12 AM
I meant where is the function defined?oh. that part I don't know. i actually got it to work using 'substr' in my html code. I know that's not how the script intended for it to work, but it does work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum