Jump to content

function in an sql query statement


poe

Recommended Posts

i cant get this to work, i want to take the title from my db and remove all non-alphanumeric characters, then reverse the title. - this 'newtitle' will be my main sort. i cant seem to figure how to include the function into my sql query statement

 

myfunc($intput) {
$intput = preg_replace("/[^a-z0-9]/i", "", $input);
strrev($intput);
return $input;
}
  
$links = $db->GetAll(" SELECT *, myfunc(`TITLE`) as `NEWTITLE` FROM `{$tables['link']['name']}` WHERE `STATUS` = '2' AND `CATEGORY_ID` = ".$db->qstr($id)."  ORDER BY `NEWTITLE` ASC ");

 

Link to comment
https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/
Share on other sites

i cant get this to work,

 

And you never will.

 

When you call mysql_query() it goes to the MySQL server for processing and it doesn't even know or care that PHP exists. You can use functions in MySQL but they have to be native MySQL functions (eg NOW(), DATE_FORMAT() etc) or your own custom MySQL function defined in MySQL itself.

$links = $db->GetAll(" SELECT *

              FROM `{$tables['link']['name']}`

              WHERE `STATUS` = '2'

              AND `CATEGORY_ID` = ".$db->qstr($id)." 

              ORDER BY `TITLE` ASC ");

 

then use the function when you process the results in your php script

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.