Jump to content


Photo

using multiple trunc ?? Help needed!!


  • Please log in to reply
1 reply to this topic

#1 stuart.cole

stuart.cole
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 12 October 2006 - 08:11 PM

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!


<? $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;
}
?>


#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 October 2006 - 10:15 AM

Stuart,

I've replied to this in your other post... Please don't double post!

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users