Bluehost.com Web Hosting $6.95

show x characters from longtext ?

This is a discussion on show x characters from longtext ? within the MySQL Database forums, part of the Database Forums category; Hi all, This is my very first post .... In my table called 'content ' I have field called 'story', this is ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-14-2006
= poster =
 
Posts: n/a
Default show x characters from longtext ?

Hi all,

This is my very first post ....

In my table called 'content ' I have field called 'story', this is a
longtext field .

When I do :

SELECT story FROM homecontent WHERE = 1 ;
Mysql returns the whole 'story' from 'homecontent' where id is 1 ....
Nothing wrong with this, but I want Mysql to show only the first 100
characters from 'story' ....

How can this be done ?

thanks ,


Reply With Quote
  #2 (permalink)  
Old 12-14-2006
Captain Paralytic
 
Posts: n/a
Default Re: show x characters from longtext ?


= poster = wrote:
> Hi all,
>
> This is my very first post ....
>
> In my table called 'content ' I have field called 'story', this is a
> longtext field .
>
> When I do :
>
> SELECT story FROM homecontent WHERE = 1 ;
> Mysql returns the whole 'story' from 'homecontent' where id is 1 ....
> Nothing wrong with this, but I want Mysql to show only the first 100
> characters from 'story' ....
>
> How can this be done ?
>
> thanks ,


How can this be done ?

Well the first step is to look at the MySQL manual
http://dev.mysql.com/doc/refman/5.0/en/index.html

Then when looking at the manual in the table of contents you will read
the words:
"12 Functions and Operators "
Which will lead you to another table of contents for this section which
contains the words:
"12.3. String Functions"

Can you see how this is building up? It is the standard hierarchical
method often used in writing manuals.

Anyway, clicking on the "String Functions" link takes one to:
http://dev.mysql.com/doc/refman/5.0/...functions.html

Where one discovers functions for handling strings. Two of these which
closely relate to your question are:

LEFT(str,len)

and

SUBSTRING(str,pos) (or SUBSTR()).

You then have to read the details of how to use either of those
functions and put them into your query. Following the numerous
examples supplied in the manual is usually a good starting point.

So that is how it is done.

You will find that this method (i.e. reading the manual) can be applied
to lots of queries that you will encounter when working with all manner
of things.

HTH

Regards,

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:21 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0