Hello there I have a code here that gets the decription of a certain product out of a database. How can I limit the output to 400 characters? Here is the code: <?php if ($row_inventory["v_descr"]) { echo $row_inventory["v_descr"]; } else { echo 'N/A'; } ?> PHP:
http://www.php.net/manual/en/function.substr.php echo substr( $row_inventory["v_descr"], 0, 400); Code (markup): Or something like that...
You can also use mysql's substring function to just pick 400 characters. Saves on bandwidth from the database.
Paste the code that pulls the data from the database... Looks like "SELECT * FROM products WHERE products_id = 'N'.
Get the first N characters is not always the best choice because some time the word is incomplete. You can think of first 20 words, for example. However, in this case, the mySQL query is like: $query="SELECT SUBSTRING( article_text, 1, 400 ) AS shorttext FROM articles WHERE article_id=101"; PHP: