need some help

Started on the old forum in August 2012 · view the original in the archive · old links redirect here

#adz #adzvilla

15 replies · 895 views · started 14 years ago · 1 min read

4 participants
razor Developer · 52 posts #1

i can't understand why ads are also showing when it is paused , please can any1 tell me what is wrong in this ?

$advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
		while($advid = mysql_fetch_array($advids))
		{
			if($adult == 'adult')
			{
				$sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
			}
			else
			{
				$sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND adult='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
			}
			while($ad = mysql_fetch_array($sql))
			{
				$t = htmlspecialchars($ad['title']);
				$l = htmlspecialchars($ad['link']);
.........................

in database paused=1 but still ads are showing , why?

xor Junior · 13 posts #2

razor wrote: i can't understand why ads are also showing when it is paused , please can any1 tell me what is wrong in this ?

$sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND paused='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());

.........................

in database paused=1 but still ads are showing , why?

following the OR keyword include the paused='0' column

razor Developer · 52 posts #3

thanks bro, thank you again for sorting my logical mistake...

razor Developer · 52 posts #4

one more problem plz help

if(!empty($uid) && !empty($adult))
	{
		$advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
		while($advid = mysql_fetch_array($advids))
		{
			if($adult == 'adult')
			{
				$sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND paused='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
			}
			else
			{
				$sql = mysql_query("SELECT * FROM adverts WHERE paused='0' AND countries LIKE '%$country%' OR countries='WORLD' AND paused='0' AND adult='0' AND userid='$advid[0]' AND approved='1' ORDER BY RAND() LIMIT 5") or die(mysql_error());
			}
			while($ad = mysql_fetch_array($sql))
			{
				$t = htmlspecialchars($ad['title']);
				$l = htmlspecialchars($ad['link']);
				mysql_query("UPDATE adverts SET imps=(imps+1) WHERE id='".$ad['id']."'") or die(mysql_error());
				mysql_query("UPDATE advertiser SET today_imps=(today_imps+1), total_imps=(total_imps+1) WHERE id='".$ad['userid']."'") or die(mysql_error());
				echo"<div class='adbox'>";
					$ph = explode(" ",$ua);
					$title = str_ireplace(":phn:", "$ph[0]", "$t");
					$av = $ad['userid'];
					$pb = $uid;
					$ad = $ad['akey'];
					$rn = str_shuffle('ADZVILLA.COM');
					$converter = new Encryption;
					$str = $rn.'-'.$av.'-'.$pb.'-'.$ad.'-'.$country;
					$encoded = $converter->encode($str);
					echo"<sup><font color=\"red\"><small>ad </small></font></sup><a href='".SITE_URL."/serve/click/".urlencode($encoded)."'>$title</a>";
				echo"</div>";
			}

code is like this but the problem i want to show only 5 random ads , but its not showing only five, what is the mistake plz help any1...

xor Junior · 13 posts #5

What is the output, how many records are shown? What script is that, i think the entire script needs to be benchmark/Optimize with such query. Thus those query could be join to prevent heavy resource from what I've seen.

razor Developer · 52 posts #6

xor wrote: What is the output, how many records are shown? What script is that, i think the entire script needs to be benchmark/Optimize with such query. Thus those query could be join to prevent heavy resource from what I've seen.

it is showing all the active ads look here http://adzvilla.com/serve/ads/4/adult

razor Developer · 52 posts #7

xor wrote: What is the output, how many records are shown? What script is that, i think the entire script needs to be benchmark/Optimize with such query. Thus those query could be join to prevent heavy resource from what I've seen.

it is showing all the active ads look here http://adzvilla.com/serve/ads/4/adult use mobile browser

xor Junior · 13 posts #8

Its showing exactly 5 records.

xor Junior · 13 posts #10

The query seems ok, as its limited to 5, to get a better understanding of these queries id have to rewrite them, however to hard-code it add these 2 lines

<?PHP
//first line
$i = 0;

while($ad = mysql_fetch_array($sql))
{
	//second line
	
	if($i >= 5){
		break;
	}
	$i++;
	
	
	$t = htmlspecialchars($ad['title']);
	$l = htmlspecialchars($ad['link']);
	
	mysql_query("UPDATE adverts SET imps=(imps+1) WHERE id='".$ad['id']."'") or die(mysql_error());
	mysql_query("UPDATE advertiser SET today_imps=(today_imps+1), total_imps=(total_imps+1) WHERE id='".$ad['userid']."'") or die(mysql_error());
	
	echo"<div class='adbox'>";
	$ph = explode(" ",$ua);
	$title = str_ireplace(":phn:", "$ph[0]", "$t");
	$av = $ad['userid'];
	$pb = $uid;
	$ad = $ad['akey'];
	$rn = str_shuffle('ADZVILLA.COM');
	$converter = new Encryption;
	$str = $rn.'-'.$av.'-'.$pb.'-'.$ad.'-'.$country;
	$encoded = $converter->encode($str);
	echo"<sup><font color=\"red\"><small>ad </small></font></sup><a href='".SITE_URL."/serve/click/".urlencode($encoded)."'>$title</a>";
	echo"</div>";
}
razor Developer · 52 posts #11

sorry xor, thanks for trying to help me but it does not work, anyway i have fixed it now by changing the first while loop , there was logical problem...... anyhow thank you

xor Junior · 13 posts #12

razor wrote: sorry xor, thanks for trying to help me but it does not work, anyway i have fixed it now by changing the first while loop , there was logical problem...... anyhow thank you

The few lines of modification actually does work if u written in correctly.

Your welcome

razor Developer · 52 posts #13

at last done it... code will be

if(!empty($uid) && !empty($adult))
	{
$i=0;
		$advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
for($i=0;$i<5;$i++)
{

		$advid = mysql_fetch_array($advids);
		

			if($adult == 'adult')
			{

hmm... thanks xor for idea of looping

xor Junior · 13 posts #14

A quick note. it may work, however the syntax is invalid

//this line is not needed
$i=0;

//because you  declare var $i here in the for loop
for($i=0;$i<5;$i++)

//also, the correct way to limit results to 5 would be
$advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."' LIMIT 5");

Bare in mind that results maybe less than 5, due to the fact that you further filter the results from the above query( $adult= ) or enough rows not available.

Rksk Developer · 54 posts #15

razor wrote: at last done it... code will be

if(!empty($uid) && !empty($adult))
	{
$i=0;
		$advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."'");
for($i=0;$i<5;$i++)
{

		$advid = mysql_fetch_array($advids);
		

			if($adult == 'adult')
			{

hmm... thanks xor for idea of looping

Don't forget to use LIMIT in your query. Otherwise it will eat your RAM and slow down your site. $advids = mysql_query("SELECT id FROM advertiser WHERE id != '$uid' AND points >='".CRATE."' LIMIT 5");

nimeshka Developer · 180 posts #16

I do not understand why it shows more than 05 ads...but it is better if u can double check the lines above as well...

External image (may be gone)

I'm Proud to be a Sri Lankan!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close