NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help!! - Fixed

jose sanchez j_r_sanchez at yahoo.com
Thu May 30 10:41:14 EDT 2002


I fixed my problem. The while loop I had before was
messing things up. Here's the fixed problem:

$text_path ='NULL';
$text = array( 0,0,0,0,0 );
$text_ads_count = 5
$current = 1;

This function will be called 4 or five times per page
like this:
<tr>
<td>
<?
	get_text_ad( $current++ );
	include( $text_path );
?>
</td>
</tr>


function get_random_number( $m, $l )

{	
	srand((double) microtime() * 1000000);
	return rand( $m, $l );		
}
		

		
function get_text_ad( $cur ){
		
// declare global variables that will be used in the
function
		global $text;
		
		// declare local variable
		$useit = 'no';
		
		// set the current table to be used
		$table_name = 'ads_text';
		$update_field = 'presence';
		
		// if is the first ad displayed on the page; go
ahead and use it
		if( $cur == 1 )
		{   // set the id from a random generated number
			$id = get_random_number( 1,
$GLOBALS['text_ads_count'] );
			
			// Based on this number select the record from the
db
			$sql = "select path from $table_name where
ad_id=$id";
			
			$result = runQuery( $sql, "-- Select from
$table_name --"  );
			
			// set the path to the loaded path
			list( $GLOBALS['text_path'] ) = mysql_fetch_array(
$result );
			
			// set the current posistion in the array with the
selected id
			$text[$cur] = $id; 
					
			update_table( $table_name, $id, $update_field );			
		}// end if first occurrance
		else
		{
			while( $useit == 'no' ){
				$useit = checkit( $id = rand( 1,
$GLOBALS['text_ads_count'] ),
$GLOBALS['text_ads_count'] );
				
				if( $useit == 'yes' ){
					// Based on this number select the record from
the db
					$sql = "select path from $table_name where
ad_id=$id";
				
					$result = runQuery( $sql, "-- Select from
$table_name --" );
				
					// set the path to the loaded path
					list( $GLOBALS['text_path'] ) =
mysql_fetch_array( $result );
					
					// set the current posistion in the array with
the selected id
					$text[$cur] = $id;	
							
					update_table( $table_name, $id, $update_field );
				
				}// end if useit or not
				else
					continue; // continue looping
				
			}// end while loop
		}//end else
	}// end function get_text********************
	

	function checkit( $randomnumber, $count ){
		// set local variables with global variables' data
		$t = $GLOBALS['text'];
			
		for( $i = 1; $i <= $count; $i++ )
		{
			if( $t[$i] == $randomnumber )
				return 'no'; // don't use the number/id
		}// end for loop
		return 'yes';	 // use the number/id
	}//end function checkit**********



=====
"An ounce of gold cannot buy an ounce of time."
- Anonymous


www.whmicro.com

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



More information about the talk mailing list