Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Displaying results from multiple field query
Old 07-01-2011, 09:49 PM Displaying results from multiple field query
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
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>

Last edited by jwgrafflin; 07-01-2011 at 09:55 PM..
jwgrafflin is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-02-2011, 09:25 PM Re: Displaying results from multiple field query
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
"it won't list the url." Why not? Is it being mischievous? On strike, perhaps?

Seriously, not enough info. Are there correct values on the db to expect output of a certain form? You output $num - is that correct? What, if anything, is displayed in your generated table cells?

Given you're testing for equality change your if/elseifs to a swithc and put in a default branch to get a bit more diagnostic info.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 07-02-2011, 10:12 PM Re: Displaying results from multiple field query
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
Everything but the url is generated as desired.
jwgrafflin is offline
Reply With Quote
View Public Profile
 
Old 07-05-2011, 01:06 PM Re: Displaying results from multiple field query
Junior Talker

Posts: 3
Trades: 0
You might want to try this:

Code:
$query = "SELECT * FROM programs WHERE netname1 LIKE '%$search%' OR netname2 LIKE '%$search%' OR netname3 LIKE '%$search%' ORDER BY progname ASC";
Adding % symbol before and after your search terms makes it a "containing" search. Otherwise, your search is just the same as an "=" search. LIKE is looking for a regex pattern. So maybe enough results are not being generated? Maybe that's the problem?
adityamenon90 is offline
Reply With Quote
View Public Profile
 
Old 07-05-2011, 01:48 PM Re: Displaying results from multiple field query
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
No need for that. The correct output is there, it just won't display.
jwgrafflin is offline
Reply With Quote
View Public Profile
 
Old 08-27-2011, 11:03 PM Re: Displaying results from multiple field query
Average Talker

Posts: 25
Name: John Grafflin
Trades: 0
The "mischievous" code is no longer on "strike" and is behaving as it should once one minor little error was corrected. Problem solved, so you can close this thread.
jwgrafflin is offline
Reply With Quote
View Public Profile
 
Old 08-28-2011, 02:49 AM Re: Displaying results from multiple field query
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
No harm feelings but, your coding is a mess.
Quote:
$search="".$search.""; // ???!!! what's this?!
Anyway... I can also see that your database structure is... same as coding. What if you will need netnameurl8 ?

My way is much more simple
Code:
 // You have the result
while($record = mysql_fetch_assoc($result)){
$progname = $record['progname'];
// the below condition is a real nonsense
// what's about $netname1 ? $netname2 ? $netname3 ?
// are they initialized somewhere
/*
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");}
*/
$neturl = $record['netnameurl1'] .  $record['netnameurl2'] .  $record['netnameurl3'];
// it's not what you want but you can debug better
?>
 
<tbody class="left">
<tr>
<td><?echo $progname;?></td>
<td><?echo $neturl;?></td>
</tr>
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Reply     « Reply to Displaying results from multiple field query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.30064 seconds with 12 queries