Welcome to Help4Web.co.uk - Web Design Help, Html Tutorial, Php, Asp , SQL help and CCNA, MCSE definitions!
Google
Webkpop-web.com

     Main Menu

· Home
· Free Downloads
· Computing FAQ
· Contact Us
· Free Software Downloads
· Tech Forum
· Technology News
· Web Design Help
· Web Links
· Your Online Account
· Your PM



     Web Browser


     Website Links
Supermediastore! #1 in Computer media & Accessory

White Papers IT
Learn Korean
Chinese Pop Music
Advertise Kpop
Korean Pop Site Map
Web Design
Pop Music
Chinese Girls
HK Pop Korean Music
Lee Hyori
Hyori
Boa Park Ji Yoon
Baby Vox YG Family
Jeon Ji Hyun
1 Tym Ha Ji Won
Shyne Rain Bi
Shin Mina SM Town
Fly to the Sky
Korean Girls and Models
Nicholas Tse
161 Clan
보아
Edison Chen
Sung Hi Lee
Shinhwa
Andy Lau Jay Chou
White Papers
Case Study SES
Kelly Chen
Liu Yi Fei Sammi Cheng
Jordan Chan Music
Computer Jobs IT

Computer Help Forum and Programming Advice :: View topic - Limiting characters returned from mysql query
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log inLog in 

Limiting characters returned from mysql query

 
Post new topic   Reply to topic    Computer Help Forum and Programming Advice Forum Index -> Php
View previous topic :: View next topic  
Author Message
sam
Web Design Newbie
Web Design Newbie


Joined: Aug 18, 2004
Posts: 38

PostPosted: Mon Jan 23, 2006 9:34 pm    Post subject: Limiting characters returned from mysql query Reply with quote

Hi Guys,

Does MySQL support the limiting of characters returned from a query?

I'm trying to truncate my results (and append a ... to the end) so that they look better on my website.

Cheers
Back to top
View user's profile Send private message
Jon
Web Design Admin
Web Design Admin


Joined: Jul 12, 2004
Posts: 72

PostPosted: Mon Jan 23, 2006 9:37 pm    Post subject: Reply with quote

From manual:

Code:
SUBSTRING(str,pos), SUBSTRING(str FROM pos), SUBSTRING(str,pos,len), SUBSTRING(str FROM pos FOR len)

The forms without a len argument return a substring from string str starting at position pos. The forms with a len argument return a substring len characters long from string str, starting at position pos. The forms that use FROM are standard SQL syntax. It is also possible to use a negative value for pos. In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning. A negative value may be used for pos in any of the forms of this function.

mysql> SELECT SUBSTRING('Quadratically',5);
        -> 'ratically'
mysql> SELECT SUBSTRING('foobarbar' FROM 4);
        -> 'barbar'
mysql> SELECT SUBSTRING('Quadratically',5,6);
        -> 'ratica'       
mysql> SELECT SUBSTRING('Sakila', -3);
        -> 'ila'       
mysql> SELECT SUBSTRING('Sakila', -5, 3);
        -> 'aki'
mysql> SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
        -> 'ki'

This function is multi-byte safe.

If len is less than 1, the result is the empty string.

_________________
Free MusicCpopServer Definition
Back to top
View user's profile Send private message Visit poster's website
sam
Web Design Newbie
Web Design Newbie


Joined: Aug 18, 2004
Posts: 38

PostPosted: Mon Jan 23, 2006 9:38 pm    Post subject: Reply with quote

Thanks for that, but i cant seem to quite work out how to use it. All the examples show how to remove the begining of the string, but not how to limit the max length of the string.

Ive tried this:

"SELECT SUBSTRING(title,0,10), url FROM site_news ORDER BY id DESC LIMIT 2,7";

to no avail.
Back to top
View user's profile Send private message
Jon
Web Design Admin
Web Design Admin


Joined: Jul 12, 2004
Posts: 72

PostPosted: Mon Jan 23, 2006 9:41 pm    Post subject: Reply with quote

What does that produce? Looks like correct implementation to me..
_________________
Free MusicCpopServer Definition
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Computer Help Forum and Programming Advice Forum Index -> Php All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum







Learn Chinese | Learn cantonese | Learn Mandarin | Grace Park | Party Organisers | Kaila yu | Phone Card | Twins | Chinese Society | Loans UK | BokuMaro | CV Help Book | Chinese Wife | Korean Singles | British Born Chinese | Bae Yong Jun | Speak Korean | Chinese Models | Music | Information Security Management | Maritime Greenwich Campus | Covering Letters Help | Chinese Music | Jang Nara | SES | YG Family | Learn Korean | Firewall Definition | Server Definition | Wireless Network Definition | E-Commerce Definition | Sales Leads | Application Firewall | CCNA definitions | Research Papers | Webcast | CV Help

Author KPop Music :- Jon Bock ( Chinese Pop Music Learn Korean )
Produced by Kpop-Web Design Associates, all rights not reserved.
Internet Marketing and Search Engine Optimisation Software Defined Radio