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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 , |
|
|||
|
= 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, |
![]() |
| Thread Tools | |
| Display Modes | |
|
|