Try using MySQL to do that right in the query itself (and save the 
overhead of retreiving the whole blob then PHP'ing the blob too).

 From the MySQL Doc's   ;-)  RTFM once at least
----------------------------------------------
SUBSTRING(str,pos,len)
SUBSTRING(str FROM pos FOR len)
MID(str,pos,len)
Returns a substring len characters long from string str, starting at 
position pos. The variant form that uses FROM is ANSI SQL92 syntax.

mysql> select SUBSTRING('Quadratically',5,6);
         -> 'ratica'
----------------------------------------------


For your problem it might look like
$sql = SELECT field1, field2, SUBSTRING(blobfieldname,0,160) FROM 
articles where ....

( BTW I usually assume prox 8 chars per word for something like this so 
20 wds x 8 char = 160 chars total  BUT you might have lots of esoterica 
in there and might want to adjust that ;-) )


HTH
Tom Henry



Cilfa wrote:
> Hi,
> 
> On my website I want to display some articles, in Slashdot style. The
> main page should only display the first 20 words of the article, and
> users should be able to click on a link to view the entire article.
> The articles are stored in a MySQL database, the body of the article in a
> blob-field.
> 
> My question is this: how can I select only those first 20 words in the
> PHP code?
> 
> I hope somebody can help me with this.
> 
> Cilfa
> 
> 



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to