TheCatapult Posted April 18, 2012 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 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 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
Archived
This topic is now archived and is closed to further replies.