Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.