What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Perform Function on SQL Query Lookup?

Perform Function on SQL Query Lookup?
Author: Message:
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
RE: Perform Function on SQL Query Lookup?
I'll save you the trouble.

I use this in my CMS which is floating around on the MyBB site, MyBB ideas, new MyBB Mods site, and all of my client sites.

This function is directly from the CMS module which builds the friendly page URLs, checking for duplicates, appending numbers etc.

Modify as needed:
code:
function build_friendly_title($title, $page_id=0, $parent_id=0)
{
    global $db;
   
    $friendly_title = strtolower($title);
    $friendly_title = preg_replace("#\s#", "-", $friendly_title);
    $friendly_title = preg_replace("#([^a-zA-Z0-9-_])#", "", $friendly_title);
    $test_title = $friendly_title;
    $i = 1;
    if($page_id > 0)
    {
        $page_id_add = " AND page_id != '$page_id'";
    }
    do
    {
        $query = $db->query("SELECT friendly_title FROM pages WHERE friendly_title='$test_title' $page_id_add AND parent_id='".intval($parent_id)."' ORDER BY page_id ASC LIMIT ".($i-1).", 1");
        $existing_page = $db->fetch_array($query);
        if($existing_page['friendly_title'])
        {
            $i++;
            $test_title = $friendly_title."-".$i;
        }
    }
    while($existing_page['friendly_title']);
    return $test_title;
}


You can, however, also define functions in MySQL - but they won't work with PHP callbacks etc.
08-21-2007 01:42 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Perform Function on SQL Query Lookup? - by Dempsey on 08-21-2007 at 12:48 PM
RE: Perform Function on SQL Query Lookup? - by Veggie on 08-21-2007 at 01:41 PM
RE: Perform Function on SQL Query Lookup? - by surfichris on 08-21-2007 at 01:42 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On