argh...shuffle() not working for banner exchange

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

argh...shuffle() not working for banner exchange

Post by m3mn0n »

:evil: i've been struggling with the updating of this script for a friend, when i have it finally finished after one hell of a long week, i find that the final output(user's banner code) doesn't even work properly.

Here is what it displayed:
bannercode.html wrote: Warning: Wrong datatype in shuffle() call in C:\apache\htdocs\c2\view.php on line 15

Warning: Wrong datatype in shuffle() call in C:\apache\htdocs\c2\view.php on line 17

Warning: Wrong datatype in shuffle() call in C:\apache\htdocs\c2\view.php on line 24

Warning: Wrong datatype in shuffle() call in C:\apache\htdocs\c2\view.php on line 26

Warning: Supplied argument is not a valid MySQL result resource in C:\apache\htdocs\c2\view.php on line 32

Warning: Cannot add header information - headers already sent by (output started at C:\apache\htdocs\c2\view.php:15) in C:\apache\htdocs\c2\view.php on line 49

Warning: Cannot add header information - headers already sent by (output started at C:\apache\htdocs\c2\view.php:15) in C:\apache\htdocs\c2\view.php on line 50
ugh... the shuffle() command is one line 15 and i think that is what's triggering everything else to fail. I will copy and paste the code here if anyone wants to take a look...

Code: Select all

<?
	$eligable=mysql_query("select id from banneruser where approved='1' and credits >= 1 and id != '$uid'");
	$get_number=mysql_num_rows($eligable);
	if($get_number == 0){
		$eligable=mysql_query("select id from banneruser where defaultacct='1' and id != '$uid'");
		}else{
	}
	while($rand_rows = mysql_fetch_array($eligable)){
				$id_arrayї] = $rand_rowsїid];
			}
			srand((double)microtime()*1000000); 
			shuffle($id_array);
			srand((double)microtime()*1000000); 
			shuffle($id_array);
			$pick = $id_arrayї0];
			$get_banner = mysql_query("select bannerurl from bannerurls where uid='$pick'");
			while($rand_ban = mysql_fetch_array($get_banner)){
				$ban_arrayї] = $rand_banїbannerurl];
			}
			srand((double)microtime()*1000000); 
			shuffle($ban_array);
			srand((double)microtime()*1000000); 
			shuffle($ban_array);
		
	$banner=$ban_arrayї0];
	$cookieuid=$HTTP_COOKIE_VARSїcookieuid];
	$ip = getenv ("REMOTE_ADDR");
	$raw_query=mysql_query("select raw,lastip from banneruser where id=$pick");
	$get_raw=mysql_fetch_array($raw_query);
	$rawcode=$get_rawїraw];
	if($rawcode != ''){
	$time = mktime()+$cookie_expire;
	$date = date("l, d-M-y H:i:s", ($time));
		if($cookieuid != $uid){
	header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
	setcookie("cookieuid",$uid, time()+$cookie_expire);
	echo "$rawcode";
				$update_id=mysql_query("update banneruser set credits=credits+1,lastip='$ip' where id=$uid");
				$update_bid=mysql_query("update banneruser set exposures=exposures+1, credits=credits-1 where id=$pick");
			}else{
			echo "$rawcode";
			$update_bid=mysql_query("update banneruser set exposures=exposures+1, credits=credits-1 where id=$pick");
			}
	}else{
			if($cookieuid != $uid){
		header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
		setcookie("cookieuid",$uid, time()+$cookie_expire);
?>
<a href="<? echo "$base_url"; ?>/click.php?uid=<? echo "$uid"; ?>&bid=<? echo "$pick"; ?>" target=_blank><img src="<? echo "$banner"; ?>" border=0 width=468 height=60></a>
<?
		$update_id=mysql_query("update banneruser set credits=credits+1,lastip='$ip' where id=$uid");
		$update_bid=mysql_query("update banneruser set exposures=exposures+1, credits=credits-1 where id=$pick");
	}else{
?>
<a href="<? echo "$base_url"; ?>/click.php?uid=<? echo "$uid"; ?>&bid=<? echo "$pick"; ?>" target=_blank><img src="<? echo "$banner"; ?>" border=0 width=<? echo "$banner_width"; ?> height=<? echo "$banner_height"; ?>></a> 
<?
	$update_bid=mysql_query("update banneruser set exposures=exposures+1, credits=credits-1 where id=$pick");
		?>
<?
}
	}
		?>
if it helps, the id is a number so it really doesn't make sence for this not to work, what other data types go with shuffle()?! :x
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

After your while loop put

Code: Select all

echo '<pre>';
print_r($id_array);
echo '</pre>';
to check that that variable is being set properly.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

add a

Code: Select all

ORDER BY rand()
to your query and you may skip the whole php-shuffle thing ;)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

whoa! you can rand() within a query? never knew that one.. :o

anything else possibly wrong?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

tell us ;)

have you tried?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

both didn't work. :cry:
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

anyone else have some suggestions?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Oromian wrote:both didn't work. :cry:
Does this mean that nothing is being passed for $id_array?

Mac
Post Reply