MyBB Community Forums

Full Version: Nitemares Mod List
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
it works for methats the exact code i'm runing on my forum

if ($ads['aid'] == $ran and $ads['mode'] != "3" and $ads['mode'] != "4"){
$blah = "1";
}

that changes it to 1, i HAVE tested my plugins, i run them on my own forums
I believe if you dont have any initial ads set, then it will never be set to 1. Try putting in some code to check if their are any ads in the first place. and then decide what to do next
nitemare, do you have a reason why you use eval so much?
fixed and uploading
Here's an idea for you:
function do_ads()
{
	global $db, $templates, $footer, $banner;

	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."ads WHERE mode != '3' AND mode != '4' ORDER BY RAND() LIMIT 1");
	$ads = $db->fetch_array($query);

	if($ads['aid'])
	{
		if ($ads['mode'] == 2){
			$new = $ads['shown']+1;
			if ($new < $ads['max']){
				$db->query("UPDATE ".TABLE_PREFIX."ads SET shown='".$new."' WHERE aid='".$ads['aid']."'");
			}else{	
				$db->query("UPDATE ".TABLE_PREFIX."ads SET mode='4' WHERE aid='".$ads['aid']."'");
			}
		}
		
		$banner = $ads['code'];
	}
	else
	{
		$banner = ''; // no banner
	}
}

Tikitiki says it works.
Indeed it does Smile

(its raining, and the suns out o.o)
i've heard his "suggestion", but i'm not going to change it right now, cuz i have to understand it first
function do_ads()
{
	global $db, $templates, $footer, $banner;

        // Select one banner at random
	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."ads WHERE mode != '3' AND mode != '4' ORDER BY RAND() LIMIT 1");
	$ads = $db->fetch_array($query);

        // Continue ONLY IF their are ads on the forum
	if($ads['aid'])
	{
                // Is there a limit to the number of ads shown?
		if ($ads['mode'] == 2){
                         // Add a view to the view count
			$new = $ads['shown']+1;
                        // Update only if the max number of ads have not been shown
			if ($new < $ads['max']){
                        // Run the update
				$db->query("UPDATE ".TABLE_PREFIX."ads SET shown='".$new."' WHERE aid='".$ads['aid']."'");
			}else{	
                        // The max number of ads have been reached. Dont show the ad
				$db->query("UPDATE ".TABLE_PREFIX."ads SET mode='4' WHERE aid='".$ads['aid']."'");
			}
		}
		// The banner equals the ad code
		$banner = $ads['code'];
	}
	else
	{
                // Theirs no banners; dont set anything
		$banner = ''; // no banner
	}
}

Check out the comments Smile
Comments on the query I posted.
// Select one banner at random
$query = $db->query("
SELECT * ". // Select all the fields
" FROM ".TABLE_PREFIX."ads". // From the table
" WHERE mode != '3' AND mode != '4'". // that are not mode = 3 and not mode = 4
" ORDER BY RAND()". // Order the results by random
" LIMIT 1"); // Just get 1 row.

Commenting on yours:
	$blah = "0";
	while ($blah != "1"){
		// This query find the largest aid in the ads table, however, it does not take into account any aids that may be missing (deleted, or otherwise)
		$count = $db->query("SELECT MAX(aid) AS aid FROM ".TABLE_PREFIX."ads");
		// This query selects all the rows of the table and returns it to PHP.  This is an inefficient way to count the number of rows of the table since you can go SELECT COUNT(*) FROM ".TABLE_PREFIX."ads, and it won't make MySQL work as hard.
		$count2 = $db->query("SELECT * FROM ".TABLE_PREFIX."ads");
		// Also, since the stuff in the ads table probably won't change each time you loop the 'while', you should at least put the above two queries outside the loop, so it doesn't have to fetch the maximum number and the number of rows of the table each time the loop is executed.
		$num = $db->fetch_array($count);
		$ran = rand(1,$num['aid']);
		if (mysql_num_rows($count2) == "0"){
			$blah = "1";
		}
       	$query = $db->query("SELECT * FROM ".TABLE_PREFIX."ads WHERE aid='".$ran."'");
		$ads = $db->fetch_array($query);
		if ($ads['aid'] == $ran and $ads['mode'] != "3" and $ads['mode'] != "4"){
			$blah = "1";
		}
	}
	
	if ($ads['mode'] == 2){
		$new = $ads['shown']+1;
		if ($new < $ads['max']){
			$db->query("UPDATE ".TABLE_PREFIX."ads SET shown='".$new."' WHERE aid='".$ran."'");
		}else{	
			$db->query("UPDATE ".TABLE_PREFIX."ads SET mode='4' WHERE aid='".$ran."'");
		}
	}

     eval("\$banner = \"".addslashes($ads['code'])."\";");
	//$banner = addslashes($ads['code']);
}	

is their anyway you can get prospects to look at how many hits they have left?
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14