WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2004, 04:18 PM
WebProWorld Pro
 

Join Date: Feb 2004
Posts: 246
pdstein RepRank 0
Default Is there a "within" function in MySQL?

I'm writing some PHP/MySQL code to do affiliate tracking based on the referral URL. Each affilate has already supplied the baseURL of their website. An affilate that has their own domain name would have a baseURL of http://www.MyDomain.com but an affiliate that's on a free server might have a baseURL of http://www.freeserver.com/mydir/

So, what I want to do is when somebody clicks through our homepage I take the referring URL (the URL where they came from) and compare it to the affilates' baseURLs to see which affiliate (if any) the visitor came from. Something like...

SELECT * from affiliate where baseURL WITHIN 'http://www.freeserver.com/mydir/home.html'

would match a row where baseURL is http://www.freeserver.com/mydir/

SELECT * from affiliate where baseURL WITHIN 'http://www.freeserver.com/mydir/subdir/page6.html'

would also match a row where baseURL is http://www.freeserver.com/mydir/

This way an affiliate can link to us from any page in their site and we know the referral came from them.

It's kind of the opposite of the LIKE function. With the LIKE function you start with a sub-string and match it to any string that has the sub-string within it. With the WITHIN function I'm looking for I am starting with the larger string and want to match it to any string that is a sub-string of it.

Is there a function that works like a "within" function?

- Paul
Reply With Quote
  #2 (permalink)  
Old 10-21-2004, 01:34 AM
WebProWorld New Member
 

Join Date: Oct 2004
Location: sb in us
Posts: 12
dr.p RepRank 0
Default Re: Is there a "within" function in MySQL?

If you just want to match `baseUrl` values to URL's minus the html page (if present) then just strip the file name from the URL and use something like:

Code:
Select * From xtable Where xurl REGEXP "^http://yoururl.com/dir/"
Look at "SELECT" function in MySQL manual for details on REGEXP.

Regardless of what URL you're using:
~http://yoururl.com/dir/page1.html
~http://yoururl.com/dir/page2.html
~http://yoururl.com/dir/page100.html

You should use the document root (http://yoururl.com/dir/) instead of the documents themselves.
__________________
"Oh Peter. You're what the Spaniards call El Terrible" ~ Cleveland of "Family Guy"
Reply With Quote
  #3 (permalink)  
Old 11-16-2004, 11:09 PM
godzilla's Avatar
WebProWorld Member
 

Join Date: Aug 2003
Location: Montreal, CA
Posts: 68
godzilla RepRank 0
Default

In general it is suggested to reduce the search criteria rather then increasing the key value. That is, as dr.p mentions I would reduce the referrer adress to meet my needs.

But you may just as test try something like

WHERE baseURL+'%' LIKE 'http://www.freeserver.com/mydir/home.html'

'+' is usually used in sql to concatenate strings and may work for this case also...
Try and tell me.
__________________
Everything has its reason.
Your greatest glory doesn't consist in falling, but rising every time you fall and this is what defines a perfect human.
Godzilla's pass-time
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0