Jump to content

using multiple trunc ?? Help needed!!


stuart.cole

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]
Link to comment
https://forums.phpfreaks.com/topic/23793-using-multiple-trunc-help-needed/
Share on other sites

Archived

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

×
×
  • Create New...

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.