0
PHP: put first 20 chars of a db field in a string
New Here
,
/t5/dreamweaver-discussions/php-put-first-20-chars-of-a-db-field-in-a-string/td-p/489991
Jun 11, 2006
Jun 11, 2006
Copy link to clipboard
Copied
hi guys,
hopefully an easy problem you can help me with,
i have a field in a sql db that holds a users news post (varchar 500 chars long) , i have a box on my frontpage that
shows the latest 5 news posts, so i need to know how to either put the first 20 chars from the db field into a string to
display in this summary box or just how to limit the output in the box itself.
hope that makes sense.
the code below might help, "newspost" holds the data i need:
<?php echo $row_commentsset['newspost']; ?>
thanks
ted.
hopefully an easy problem you can help me with,
i have a field in a sql db that holds a users news post (varchar 500 chars long) , i have a box on my frontpage that
shows the latest 5 news posts, so i need to know how to either put the first 20 chars from the db field into a string to
display in this summary box or just how to limit the output in the box itself.
hope that makes sense.
the code below might help, "newspost" holds the data i need:
<?php echo $row_commentsset['newspost']; ?>
thanks
ted.
TOPICS
Server side applications
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/dreamweaver-discussions/php-put-first-20-chars-of-a-db-field-in-a-string/m-p/489992#M188517
Jun 11, 2006
Jun 11, 2006
Copy link to clipboard
Copied
tedrodgers wrote:
> i have a field in a sql db that holds a users news post (varchar 500 chars
> long) ,
If you're using MySQL, the VARCHAR columns hold a maximum of 255
characters on versions prior to MySQL 5.0. Does your remote server run
MySQL 5? If not, you need to change the column type to TEXT.
i have a box on my frontpage that
> shows the latest 5 news posts, so i need to know how to either put the first
> 20 chars from the db field into a string to
> display in this summary box or just how to limit the output in the box itself.
In your SQL query:
SELECT LEFT(newspost, 20) AS newspost
FROM tableName
That selects the first 20 characters. Sounds like just what you want.
--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
> i have a field in a sql db that holds a users news post (varchar 500 chars
> long) ,
If you're using MySQL, the VARCHAR columns hold a maximum of 255
characters on versions prior to MySQL 5.0. Does your remote server run
MySQL 5? If not, you need to change the column type to TEXT.
i have a box on my frontpage that
> shows the latest 5 news posts, so i need to know how to either put the first
> 20 chars from the db field into a string to
> display in this summary box or just how to limit the output in the box itself.
In your SQL query:
SELECT LEFT(newspost, 20) AS newspost
FROM tableName
That selects the first 20 characters. Sounds like just what you want.
--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

