DeathStar Posted March 22, 2007 Share Posted March 22, 2007 hi there. I want to limit an output from an query to dispaly only the first x leters. the coulom looks like this: | Text | ------------------ | Data from a post| I think its a LIMIT command but cant find such a sql command on google ?!? I'm trying to do this with: $reson = mysql_query("SELECT reson FROM users LIMIT 10"); echo $reson; Link to comment https://forums.phpfreaks.com/topic/43834-limiting-output/ Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 You want the 10 first letters or records? For records, you are right- you use LIMIT 10. But for letters, you need to use the substr() function: <?php $text = "abcdefghijklmnopqrstuvwxyz"; echo substr($text, 0, 10); //Output- first 10 chars- abcdefghij ?> Orio. Link to comment https://forums.phpfreaks.com/topic/43834-limiting-output/#findComment-212795 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 and to find out if it is even 10 letters long it would be? $string1 = ($s['string']); ubstr($string1, 0, 10) = ($s['string2']); $find = ($strino); // and there i got lost... Link to comment https://forums.phpfreaks.com/topic/43834-limiting-output/#findComment-212807 Share on other sites More sharing options...
Orio Posted March 22, 2007 Share Posted March 22, 2007 <?php function max_10 ($str) { if(strlen($str) <= 10) return $str; else return substr($str, 0, 10); } ?> Orio. Link to comment https://forums.phpfreaks.com/topic/43834-limiting-output/#findComment-212812 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 Edited a bit.. if(strlen($str) <= 10){ echo "$str";} else{ $substr = substr($str, 0, 10); echo "$substr..."; } Thanks Link to comment https://forums.phpfreaks.com/topic/43834-limiting-output/#findComment-212819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.