Page 1 of 1
Only showing part of a MySql query,like showing description?
Posted: Sat Jul 26, 2003 6:57 pm
by like_duh44
I have a website that gets a product description from a MySql database. The description is then displayed on a page where you can select the product to buy. Is there some code that can only display like the first 200 letters of the query? If you want to check out the site, its
http://www.pcandrepair.tk and click on Products.
Posted: Sat Jul 26, 2003 7:08 pm
by tsg
Code: Select all
<?php
if(strlen($description) > 200) {
$description = substr_replace($description, "...", 200);
} else {
$description = "$description";
}
?>
Posted: Sat Jul 26, 2003 11:36 pm
by like_duh44
Thank you very much. Couldnt have done any better myself
...
Posted: Sat Jul 26, 2003 11:53 pm
by kettle_drum
Note: if you only have room for a specifc amount of characters then remember that your adding the ... on the end which is 3 more.
<?php
if(strlen($description) > 200) {
$description = substr_replace($description, "...", 197);
} else {
$description = "$description";
}
?>
makes sure that you take that into account.