Displaying results from multiple field query

Here’s the scenario. I have numerous affiliate programs I promote through affiliate networks such as Commission Junction, Cleverbridge and LinkShare. Some of those affiliate programs list with more than one affiliate network.

I list the individual program in my database as "progname" and the associated affiliate network(s) as "netname1", "netname2" and "netname3" with corresponding referral urls for the associated affiliate program as "netnameurl1", "netnameurl2" and "netnameurl3."

My desired output is a list of affiliate programs and their matching referral url where the affiliate network name matches the search criteria.

For example, let’s say affiliate program "freelancer.com" is listed with both Commission Junction and LinkShare and my search term is Commission Junction. For that particular program, LinkShare is entered as "netname1" and Commission Junction is entered as "netname2" (network listing order may vary for other programs). My desired output would be:

freelancer.com http://www.cj.com/?id=jwg

If my search term was LinkShare, the desired output would be:

freelancer.com http://www.ls.com/?id=gra

Here’s what I have so far, but it won’t list the url.

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" >
<head>
<meta name="robots" content="noindex, nofollow"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="http://www.jwgmg.com/styles/style2.css"/>
<title>Search Results for Affiliate Program Database</title>
<base target="_blank" />
</head>
<body>
<div style="width: 100%; padding: 1em; text-align: center; margin: auto">
<p class="center bold lg em">Program by Network Search Results</p>
<?
include("dbinfo.inc.php");
 
$search="".$search."";
 
$query = "SELECT * FROM programs WHERE netname1 LIKE '$search' OR netname2 LIKE '$search' OR netname3 LIKE '$search' ORDER BY progname ASC";
$result=mysql_query($query)or die(mysql_error());
 
$num=mysql_num_rows($result);
$i=0;
 
 
?>
<h1><?echo $search;?></h1>
<table style="border: 1px solid black; text-align: center; margin: auto">
<thead style="background-color: #369; color: white">
<tr>
<th>Program Name</th>
<th>Referral URL</th>
</tr>
</thead>
 
<?
while($i< $num){
$progname=mysql_result($result,$i,"progname");
if($netname1=="$search"){$neturl=mysql_result($result,$i,"netnameurl1");}
elseif($netname2=="$search"){$neturl=mysql_result($result,$i,"netnameurl2");}
elseif($netname3=="$search"){$neturl=mysql_result($result,$i,"netnameurl3");}
?>
 
<tbody class="left">
<tr>
<td><?echo $progname;?></td>
<td><?echo $neturl;?></td>
</tr>
 
<?
++$i;
}
?>
</tbody>
</table>
<table style="margin-left: 12em; border: 2px solid red">
<tr><td style="background-color: #369; color: white"><?echo $num;?></td></tr>
</table>
</div>
</body>
</html>


View full post on Tycoon Talk

, , , , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes


RSS Site FeedRSS Site Feed

© 1992-2011 DC2NET™, Inc. All Rights Reserved