开发者

PHP Mysql content sneak peek

Just wondering if anyone has got any ideas regarding sneak-peaking the content of a mysql table?

Ie. say there are 10 posts with 500 words each. I want to list all the posts with a content sneak peak... i.e display a couple of lines or 200 characters etc. for each post

The thing i'm wondering is how to do that while keeping server workload as low as possible. I could load the entire content and then remo开发者_如何学Cve what I dont want with the use of substr, but I have a feeling thats not the best way.

Thanks in advance


You could use the MySQL function LEFT to get the first 200 characters from each post from the database:

SELECT LEFT(content, 200) FROM post

If you want a specific part of the content and not just the first 200 characters you could store that separately in the database, for example a column called sneak_peak. You can calculate the content of this column once using whatever method you like and persist the result. Fetching it from the database will then be very fast as no string manipulations will need to be done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜