Page 1 of 1

possible in sql?

Posted: Sun Apr 09, 2006 10:59 pm
by s.dot
I use a query that looks like this to manipulate a database field

Code: Select all

$result = mysql_query("SELECT `description` FROM `users` WHERE `id` = '{$array['id']}' LIMIT 1") or die(mysql_error());

$array = mysql_fetch_assoc($result);

$description = substr(strip_tags($array['description'],0,100));
What this is doing is selecting the description field, stripping HTML out of it, and returning the first 100 characters in $description.

Instead of selecting the entire description field (which can be lengthy) and loading it into memory.. is it possible to do something similar to this in the SQL query?

Posted: Mon Apr 10, 2006 12:15 am
by feyd
the strip_tags is not possible without a lot of effort, but the substring is with SUBSTRING()

Posted: Mon Apr 10, 2006 1:45 am
by s.dot
Yes, that's one of the things I was looking for, thanks.

However, doing SUBSTRING() wouldn't really be of use, because lets say i select the first 1000 characters.... those could all be a stylesheet, and the actual characters i'm looking for would be after that.

I guess I'll have to stick with loading it all into an array and then freeing it as soon as possible.

Posted: Wed Apr 12, 2006 7:35 am
by ntbd
Could you not make a plain_description field and insert both the description and strip_tags'ed description? Would use up more space on your db but improve the speed. Choice between the two!