Only showing part of a MySql query,like showing description?
Moderator: General Moderators
-
like_duh44
- Forum Commoner
- Posts: 63
- Joined: Sat Jul 26, 2003 6:57 pm
Only showing part of a MySql query,like showing description?
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.
Code: Select all
<?php
if(strlen($description) > 200) {
$description = substr_replace($description, "...", 200);
} else {
$description = "$description";
}
?>-
like_duh44
- Forum Commoner
- Posts: 63
- Joined: Sat Jul 26, 2003 6:57 pm
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
...
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.
<?php
if(strlen($description) > 200) {
$description = substr_replace($description, "...", 197);
} else {
$description = "$description";
}
?>
makes sure that you take that into account.