Forum Moderators: coopster

Message Too Old, No Replies

Returning limited words from DB?

         

zink

12:06 pm on Aug 29, 2006 (gmt 0)

10+ Year Member



Hey,

Basically I have some records that have BIG product descriptions which when displayed obviously spams up my site. I just wondered, is there any way I can cap this to only return say 256 characters like...

"bla bla bla this is a description of this product... more info"

Then add the dots at the end and a more info link.

Can this be done?

Sorry to make no sense and be very vague I am in a rush as I type this :-)

Cheers

barns101

1:28 pm on Aug 29, 2006 (gmt 0)

10+ Year Member



You can either get the full description and then limit the amount that is displayed substr() [php.net], or I believe MySQL can retrieve only the first x number of characters. (I can't remember how to do the MySQL bit though!)

eelixduppy

1:40 pm on Aug 29, 2006 (gmt 0)



With MySQL, have a query that looks something like this:

$query = "SELECT SUBSTRING(description,1,256) FROM table";

Something like that ;)

Good luck!

zink

1:44 pm on Aug 29, 2006 (gmt 0)

10+ Year Member



Thanks guys

Is there a way I can work it into an existing SELECT * statement?

My current code is as follows..

<---

SELECT * FROM awin WHERE MATCH(masterCategory, name, brand, description) AGAINST('+(aquascutum) +(mens men\'s mans man\'s) +( belt beanie baseball scarf bag glasses socks \"flip flops\" \"silk tie\" sandals shorts) -(jeans shirt)' IN BOOLEAN MODE) ORDER BY name

--->

description being the field I want to apply this to.

Cheers
Ben

[edited by: zink at 1:49 pm (utc) on Aug. 29, 2006]

henry0

1:49 pm on Aug 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Getting 256 char is not the best way to do it.
You are going to cut a word
What's needed is to display a pre-defined number of full words.

Zend has you answer in a good tutorial (second part)
HERE [zend.com]

zink

1:52 pm on Aug 29, 2006 (gmt 0)

10+ Year Member



Henry

That's spot on!

Would this impact on performance if I am doing this for maybe 50 products/records on a page?

Cheers
Ben

henry0

2:10 pm on Aug 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If we are speaking about 50 times say 20 words
It should not too much.
However, it depends on how many simultaneous queries could be performed.

Next we are speaking about DB optimization creating an index etc...
But I rather have another fellow WM developing that topic.
Or you could post separately a new topic either here or in database

Hope it woks