Jump to content

Something is wrong with my PHP Code


flyersman

Recommended Posts

Hi Everyone,

 

Im having trouble with my code. Its supposed to show the top 6 "credited" offers. Which means the top 6 offers with the most 1's in the status field in MySQL. Right now its just showing any 6 with 1's in status. And its showing them in ID order. Do you know whats wrong with this code. Here it is. Any help would be appreciated. Thanks!

<?
                  $rows=$mysql->doSelect("offers, offer_clicks, creatives",
			"creatives.image_link, offers.name, offers.id",
		"offers.id=offer_clicks.offer_id && offers.id=creatives.offer_id &&
		creatives.name='120x60' && offer_clicks.status>0 GROUP BY offers.id LIMIT 6");

$count_creative=0;
while($row=$rows->nextRow())
{
if($count_creative==12)
echo "</tr> <tr><td>  </td></tr> <tr>";
echo "<td><a href='creatives.php?campaign=" . $row['id'] . "'><img src='" . $row['image_link'] . "'  border='0' ><br>" . $row['name'] . "</a></td>";
$count_creative++;
}
?>

Link to comment
Share on other sites

you can add an order by and that should fix it

 


                  $rows=$mysql->doSelect("offers, offer_clicks, creatives",
			"creatives.image_link, offers.name, offers.id",
		"offers.id=offer_clicks.offer_id && offers.id=creatives.offer_id &&
		creatives.name='120x60' && offer_clicks.status>0 GROUP BY offers.id  ORDER BY offer_clicks.status DESC LIMIT 6");

Link to comment
Share on other sites

Im not sure. This is the whole code for it.

 

<?
                 $rows=$mysql->doSelect("offers, offer_clicks, creatives",
			"creatives.image_link, offers.name, offers.id",
		"offers.id=offer_clicks.offer_id && offers.id=creatives.offer_id &&
		creatives.name='120x60' && offer_clicks.status>0 GROUP BY offers.id  ORDER BY offer_clicks.status ASC LIMIT 6");
$count_creative=0;
while($row=$rows->nextRow())
{
if($count_creative==12)
echo "</tr> <tr><td>  </td></tr> <tr>";
echo "<td><a href='creatives.php?campaign=" . $row['id'] . "'><img src='" . $row['image_link'] . "'  border='0' ><br><br>" . $row['name'] . "</a></td>";
$count_creative++;
}
?>

Link to comment
Share on other sites

ok lets break it down a little so we can find the error.

 

standard  syntax for doSelect()

is

doSelect($table, $condition = " ", $selectThis = "*")

 

 

so lets set these 3 variables and see where it takes us

 

//set all the pieces for the function call

//Tables being searched
$table = "offers, offer_clicks, creatives"; 

//This is your WHERE Statement
$conditions = "WHERE offers.id=offer_clicks.offer_id AND offers.id=creatives.offer_id AND creatives.name='120x60' and offer_clicks.status>0 GROUP BY offers.id 
                    ORDER BY offer_clicks.status DESC LIMIT 6";

//Fields to view Default is "*" for all fields
$selectThis = "creatives.image_link, offers.name, offers.id"  


$rows=$mysql->doSelect($table, $condition, $selectThis)

                  

Link to comment
Share on other sites

With the code lookink like this I now get an error

 

<?
//set all the pieces for the function call

//Tables being searched
$table = "offers, offer_clicks, creatives"; 

//This is your WHERE Statement
$conditions = "WHERE offers.id=offer_clicks.offer_id AND offers.id=creatives.offer_id AND creatives.name='120x60' and offer_clicks.status>0 GROUP BY offers.id 
                    ORDER BY offer_clicks.status DESC LIMIT 6";

//Fields to view Default is "*" for all fields
$selectThis = "creatives.image_link, offers.name, offers.id"  


$rows=$mysql->doSelect($table, $condition, $selectThis)

                  
echo "</tr> <tr><td>  </td></tr> <tr>";
echo "<td><a href='creatives.php?campaign=" . $row['id'] . "'><img src='" . $row['image_link'] . "'  border='0' ><br><br>" . $row['name'] . "</a></td>";
$count_creative++;
}
?>

 

Parse error: syntax error, unexpected T_VARIABLE in /home/yourgift/domains/expressrevenue.com/public_html/new/dashboard.php on line 38

Link to comment
Share on other sites

I generally don't use auto query building functions like that.

 

if you have access to a query browser

 

try and build your string in there first.

 

something like

 

 

SELECT creatives.image_link, offers.name, offers.id FROM `offers`, `offer_clicks`, `creatives` WHERE offers.id=offer_clicks.offer_id AND offers.id=creatives.offer_id AND creatives.name='120x60' and offer_clicks.status>0 GROUP BY offers.id ORDER BY offer_clicks.status DESC LIMIT 6;

 

and fiddle with it. 

 

 

Link to comment
Share on other sites

Thanks for the help, I think though when i put ASC it worked. Weird, but it did. Now from that code (which is below) is there anyway to make it only display the ones where in the offers table available = 1? Thanks.

 

<?
                 $rows=$mysql->doSelect("offers, offer_clicks, creatives",
			"creatives.image_link, offers.name, offers.id",
		"offers.id=offer_clicks.offer_id && offers.id=creatives.offer_id &&
		creatives.name='120x60' && offer_clicks.status>0 GROUP BY offers.id  ORDER BY offer_clicks.status ASC LIMIT 6");
$count_creative=0;
while($row=$rows->nextRow())
{
if($count_creative==12)
echo "</tr> <tr><td>  </td></tr> <tr>";
echo "<td><a href='creatives.php?campaign=" . $row['id'] . "'><img src='" . $row['image_link'] . "'  border='0' ><br><br>" . $row['name'] . "</a></td>";
$count_creative++;
}
?>

Link to comment
Share on other sites

glad that worked, only display the ones with available = 1 just add it to your string

 

      $rows=$mysql->doSelect("offers, offer_clicks, creatives",
			"creatives.image_link, offers.name, offers.id",
		"offers.id=offer_clicks.offer_id && offers.id=creatives.offer_id &&  offers.available = 1 &&
		creatives.name='120x60' && offer_clicks.status>0 GROUP BY offers.id  ORDER BY offer_clicks.status ASC LIMIT 6");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.