Only showing part of a MySql query,like showing description?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
like_duh44
Forum Commoner
Posts: 63
Joined: Sat Jul 26, 2003 6:57 pm

Only showing part of a MySql query,like showing description?

Post 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.
tsg
Forum Contributor
Posts: 142
Joined: Sun Jan 12, 2003 9:22 pm
Location: SE, Alabama
Contact:

Post by tsg »

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

Post by like_duh44 »

Thank you very much. Couldnt have done any better myself
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post 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.
Post Reply