atticus Posted March 2, 2008 Share Posted March 2, 2008 Hi, I am trying to figure out the best way to limit the amount characters displayed in a result with php from a mysql database. For example, when a user clicks on the category and a list of products are shown, I would like to display the first 150 characters from the field in the database about that product with "..." following. I am a noob to php and I am not really sure where to start with this one. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 2, 2008 Share Posted March 2, 2008 in your query put LIMIT 150 Quote Link to comment Share on other sites More sharing options...
atticus Posted March 2, 2008 Author Share Posted March 2, 2008 wouldn't that just limit the amount of rows from mysql, I would actually just like to display the first 150 characters from 1 database field(row). Quote Link to comment Share on other sites More sharing options...
atticus Posted March 2, 2008 Author Share Posted March 2, 2008 alright, figured it out. Here is the solution: $newstring = substr($description,0,150); echo $newstring Quote Link to comment Share on other sites More sharing options...
corbin Posted March 2, 2008 Share Posted March 2, 2008 You could also do it with MySQL. SELECT SUBSTRING(col1, 0, 150) FROM table; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.