Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "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?

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    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));


  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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' ); 

  • #4
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    I meant where is the function defined?

  • #5
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •