Re: Show abbreviated article
| From: | Tom Henry | Date: | Tue, 14 Aug 2001 02:45:15 +0000 |
| Subject: | Re: Show abbreviated article | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11320@lists.php.net to get a copy of this message | ||
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