stuart.cole Posted October 12, 2006 Share Posted October 12, 2006 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 More sharing options...
HuggieBear Posted October 13, 2006 Share Posted October 13, 2006 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!RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23793-using-multiple-trunc-help-needed/#findComment-108245 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.