possible in sql?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

possible in sql?

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the strip_tags is not possible without a lot of effort, but the substring is with SUBSTRING()
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
ntbd
Forum Newbie
Posts: 21
Joined: Wed Apr 12, 2006 6:42 am

Post 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!
Post Reply