poe Posted May 24, 2007 Share Posted May 24, 2007 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 "); Quote Link to comment https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/ Share on other sites More sharing options...
Barand Posted May 24, 2007 Share Posted May 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/#findComment-261188 Share on other sites More sharing options...
poe Posted May 25, 2007 Author Share Posted May 25, 2007 doh! thats not what i want to hear any suggestions as to what i can do to get my desired results? thanks chris Quote Link to comment https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/#findComment-261212 Share on other sites More sharing options...
Barand Posted May 25, 2007 Share Posted May 25, 2007 $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 Quote Link to comment https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/#findComment-261220 Share on other sites More sharing options...
poe Posted May 25, 2007 Author Share Posted May 25, 2007 got ya! thankyou. chris Quote Link to comment https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/#findComment-261228 Share on other sites More sharing options...
fenway Posted May 30, 2007 Share Posted May 30, 2007 Or you could do this manipulations in SQL, with REPLACE and REVERSE. Quote Link to comment https://forums.phpfreaks.com/topic/52884-function-in-an-sql-query-statement/#findComment-264856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.