Forum Moderators: coopster

Message Too Old, No Replies

Serve Content Based On Search Variable?

How to display content based on $search_term

         

soquinn

6:58 pm on Oct 14, 2004 (gmt 0)

10+ Year Member



Hello, wondering if the is a simple php solution (or CSS) to show content or an ad based on a search variable? My client has a directory style script were the search term variable is $search_term and displays the searched phrase with relevant links on results page and the url would be:

[mysite.com...]

How can we get additional content or an ad to be displayed somewhrere on the results page for certain popular $search_term‘s and show nothing for others?

Ideas?

coopster

7:19 pm on Oct 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



One possibility is to keep an ads table in your database with keywords. Do a lookup in the ads database on keywords entered, and display the relative row(s) found in the proper format.

soquinn

8:04 pm on Oct 14, 2004 (gmt 0)

10+ Year Member



Thanks coopster, I'm not that good to write it myself and there isn't really that many keywords to require a database (maybe 15) that are popular, most come from a fixed directory link:

[mysite.com...]

but the results page is dynamic so it can't be templated for each word. Is there some code that can say, if the keyword is in the refer show this otherwise show nothing? Or if $search_term is “widget” show widget.php or widget.gif...etc.

coopster

9:39 pm on Oct 14, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure, how about a switch [php.net] control structure?
switch ($search_term) { 
case 'red_widget':
$ad = 'red_widget.gif';
break;
case 'green_widget':
$ad = 'green_widget.gif';
break;
case 'blue_widget':
$ad = 'blue_widget.gif';
break;
default:
$ad = 'black_widget.gif';
}

soquinn

2:32 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



That's interesting... do you know if you can call another php page of content like:

switch ($search_term) {
case 'red_widget':
$ad = 'red_widget.php';
break;

coopster

8:03 pm on Oct 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure. You'll want to get familiar with PHP's include() [php.net] function. Just what the doctor ordered.