Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Shorten the description to 200 caracters
Old 12-20-2007, 10:32 AM Shorten the description to 200 caracters
coldturkey's Avatar
Extreme Talker

Posts: 211
Name: Rachel
Location: Spain
Trades: 3
I have a database in mysql and i want to show only the first 200 caracters of the description and then have a read more button - where a visitor can then go on to read more.
This is my code:
PHP Code:
<table><tr><td>Description'.$UsersRow['description'].'
  
<p><a href="results.php?id='.$UsersRow['id'].'">Read More</a></td></tr></table
Can some one help me and tell me what do to do so only the first 200 caracters come out when displaying the 'description'

Thanks
Rachel
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

coldturkey is offline
Reply With Quote
View Public Profile Visit coldturkey's homepage!
 
 
Register now for full access!
Old 12-20-2007, 11:00 AM Re: Shorten the description to 200 caracters
johnncyber's Avatar
Extreme Talker

Posts: 216
Trades: 0
PHP Code:
<table><tr><td>Description'.substr($UsersRow['description'],0,200).'
  
<p><a href="results.php?id='.$UsersRow['id'].'">Read More</a></td></tr></table
For more info about substr take a look at: The PHP Manual
__________________
~Mark Romero
-Co Founder | Tech Guru,
Please login or register to view this content. Registration is FREE

-FireFox Advocate,
Please login or register to view this content. Registration is FREE

Last edited by johnncyber; 12-20-2007 at 11:01 AM..
johnncyber is offline
Reply With Quote
View Public Profile Visit johnncyber's homepage!
 
Old 12-20-2007, 11:12 AM Re: Shorten the description to 200 caracters
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Is something like this what you're looking for?
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 12-20-2007, 11:39 AM Re: Shorten the description to 200 caracters
coldturkey's Avatar
Extreme Talker

Posts: 211
Name: Rachel
Location: Spain
Trades: 3
Quote:
Originally Posted by johnncyber View Post
PHP Code:
<table><tr><td>Description'.substr($UsersRow['description'],0,200).'
  
<p><a href="results.php?id='.$UsersRow['id'].'">Read More</a></td></tr></table
For more info about substr take a look at: The PHP Manual
Thanks - that was a great help!
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

coldturkey is offline
Reply With Quote
View Public Profile Visit coldturkey's homepage!
 
Old 12-20-2007, 12:07 PM Re: Shorten the description to 200 caracters
Skilled Talker

Posts: 62
Name: Daniel
Trades: 0
i believe the term you're looking for is 'truncate'.

heres a function to help you.

PHP Code:
<?php
function trunc($string$limit) {
 if (
strlen($string) > $limit) {
  
$string substr($string0$chars);
  
$trunc_at strrpos($string' ');
  if(
$trunc_at !== FALSE) {
   
$string substr($string0$trunc_at);
  }
 }
 return 
$string;
}
?>
this will truncate to the closest word under $limit characters.
castis is offline
Reply With Quote
View Public Profile
 
Old 12-20-2007, 12:08 PM Re: Shorten the description to 200 caracters
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Also could use Mysql LEFT function http://dev.mysql.com/doc/refman/5.0/...#function_left

"SELECT * , LEFT(description, 200) AS description FROM tbl_whatever" // limits column description to 200 characters and assigns it an alias 'description'.
maxxximus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Shorten the description to 200 caracters
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24137 seconds with 12 queries