Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2007, 01:05 AM   PM User | #1
lamboe80
New to the CF scene

 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
lamboe80 is an unknown quantity at this point
"limit_words" in script not working correctly

I am using the phpMyDirectory script for a business directory site I am working on. Here's a link 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:
PHP Code:
$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:

Code:
<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?
lamboe80 is offline   Reply With Quote
Old 08-29-2007, 01:20 AM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
Where is this limit_words function?

You could use this:
PHP Code:
function limit_words($text$words){
return 
implode(' 'array_slice(explode(' '$text), 0$words));

Mwnciau is offline   Reply With Quote
Old 08-29-2007, 01:22 AM   PM User | #3
lamboe80
New to the CF scene

 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
lamboe80 is an unknown quantity at this point
Quote:
Originally Posted by Mwnciau View Post
Where is this limit_words function?

You could use this:
PHP Code:
function limit_words($text$words){
return 
implode(' 'array_slice(explode(' '$text), 0$words));

Sorry... it's on about the 14th line:
PHP Code:
$results[$key]['review'] = limit_words ($value['review'], '50' ); 
lamboe80 is offline   Reply With Quote
Old 08-29-2007, 01:39 AM   PM User | #4
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
I meant where is the function defined?
Mwnciau is offline   Reply With Quote
Old 08-29-2007, 02:12 AM   PM User | #5
lamboe80
New to the CF scene

 
Join Date: Aug 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
lamboe80 is an unknown quantity at this point
Quote:
Originally Posted by Mwnciau View Post
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.
lamboe80 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:47 AM.


Advertisement
Log in to turn off these ads.