TheCatapult Posted April 18, 2012 Report Share Posted April 18, 2012 Hi, I'm currently seeking it it is possible to limit the characters fetched from the database. For instance, there is 10000 characters and I would like to show only the first 255 character. Here's my code: <?$username="";$password="";$database="";mysql_connect("",$username,$password);@mysql_select_db($database) or die( "Unable to select database");$id="$_GET['id']";$query="SELECT * FROM news WHERE id='$id' ORDER BY id DESC LIMIT 3";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();?><?$i=0;while ($i < $num) {$bck = ($i % 2 == 0 ) ? " style=\"background:#A3FFA3\"" : " style=\"background: #B7B7E8;\"";$id=mysql_result($result,$i,"id");$title=mysql_result($result,$i,"title");$content=mysql_result($result,$i,"content");$poster=mysql_result($result,$i,"poster");?> Thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted April 18, 2012 Report Share Posted April 18, 2012 Check the string function reference, both PHP and MySQL have functions to return a portion of a string. Link to comment Share on other sites More sharing options...
smart Posted April 20, 2012 Report Share Posted April 20, 2012 u can use implode and explode function to limit the character. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now