Jump to content

Archived

This topic is now archived and is closed to further replies.

stuart.cole

using multiple trunc ?? Help needed!!

Recommended Posts

I need to limit the character count on a returned query from more than one row in the database, I can get it to limit the output for 1 row with the trunc function - but adding additional calls to the functions doesn;t seem to work - what is the best way to do it? I've tried what seems logical and have got stuck with the below which (obviously to those who understand it) doesn't work.

Help please!


[Code]
<? $query  = "SELECT * FROM News ORDER BY Time DESC LIMIT 0, 1";

$result = mysql_query($query);

function trunc($details, $max){
   if (strlen($details) > $max){
      $details = substr($details, 0, $max);
      $i = strrpos($details," ");
      $details = substr($details, 0, $i);
      $details = $details."...";
   }
   return $details;
}

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $main = trunc($row['Main'], 200);{
   $heading = trunc($row['Heading'], 75);{
   $subhead = trunc($row['Subhead'], 100); // You see the call here to the above function
   echo <<<HTML
   {$row['Date']}<br><a href="newsitem.php?id=
{$row['Newsid']}">{$heading}</a><br>{$subhead}<br>{$main}
HTML;
}
?>
[/code]

Share this post


Link to post
Share on other sites
Stuart,

I've replied to this in your [url=http://www.phpfreaks.com/forums/index.php/topic,111054.0.html]other post[/url]... Please don't double post!

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.