Jump to content

this function got error, why?


zgkhoo

Recommended Posts

    	  
<?php
    function uplinepyramid($upline2){
    	echo "<br> enter function";
    	echo "<br> upline id=".$upline2;

    	    $result2=mysql_query("SELECT * from gamecard ORDER BY Serial");
    	    
    
    	   	while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){//finding match upline
    	   		
    	      	if($row2[serialnum]==$upline2){
    	      		echo "</br>upline id=".$row2[serialnum];
    	      		$upline3=$row2[upline];
    	      		$sql="INSERT INTO gptran (GpTID)
                        VALUES
                      ('$_POST[upline]')";
                        mysql_query($sql,$con);
    	      		
    	  	      		
    	      		
    	      		
    	      		if(!empty($row2[upline])){// loop this function back
    	      			
    	      			uplinepyramid($upline3);
    	      			
    	      		}//enf if
    	      	}//end if
    	  		
    	  	}//end while
    	
    	
    }//end function


?>

 

output:

 

 

enter function

upline id=AAA0006

upline id=AAA0006

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampplite\htdocs\EN\menu\UsrCard\usraddc.php on line 174

 

enter function

upline id=AAA0001

upline id=AAA0001

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampplite\htdocs\EN\menu\UsrCard\usraddc.php on line 174

Link to comment
https://forums.phpfreaks.com/topic/76375-this-function-got-error-why/
Share on other sites

wat i want to do is....finding all the card's upline(tree mode db) from a reverse way, when find one upline then record its serial into a transaction table and record this upline earn 10 point ..

like this

downline->upline->upline->upline->upline->upline

 

 

			$sql = "CREATE TABLE gamecard
		(

		Serialnum varchar(13),
		Serial varchar(13),
		Initial varchar(13),
		Activatecode varchar(13),
		Ownerid varchar(13), 
		Status varchar(13),
		Downleft varchar(13),
		Downright varchar(13),
		Upline varchar(13),
		Expireddate datetime,
		Createdate datetime,
		Point integer(20),
		Golden varchar(15),
		Primary Key(Serialnum)

		)";

 

the cards table

Try this :

 

<?
// Recursive pyramid function.
function uplinePyramid($upline){	

// Array of data.
$data = array();

// Grab all the game cards.
$result = mysql_query("SELECT * from gamecard WHERE Serialnum = '{$upline}' ORDER BY serial");

// Have we got any results?
if(mysql_num_rows($result) > 0){
	// Build dataset.
	while($row = mysql_fetch_assoc($result)){
		$data[] = $row;
	}	
} else {
	// Return from this function // i.e. no more upline???
	return;
}

foreach($data as $d){
	insertGptran($d['Upline']);
	uplinepyramid($d['Upline']);
}

}

function insertGptran($upline){
// Insert info.
$sql = "INSERT INTO gptran(GpTID) VALUES($upline)";
mysql_query($sql);
}
?>

 

Obviously you still need to define the initial upline/serial, and it recurses as you want.

Now i'll take a look at your table. Any chance of some sample data?

Try this :

 

<?
// Recursive pyramid function.
function uplinePyramid($upline){	

// Array of data.
$data = array();

// Grab all the game cards.
$result = mysql_query("SELECT * from gamecard WHERE Serialnum = '{$upline}' ORDER BY serial");

// Have we got any results?
if(mysql_num_rows($result) > 0){
	// Build dataset.
	while($row = mysql_fetch_assoc($result)){
		$data[] = $row;
	}	
} else {
	// Return from this function // i.e. no more upline???
	return;
}

foreach($data as $d){
	insertGptran($d['Upline']);
	uplinepyramid($d['Upline']);
}

}

function insertGptran($upline){
// Insert info.
$sql = "INSERT INTO gptran(GpTID) VALUES($upline)";
mysql_query($sql);
}
?>

 

Obviously you still need to define the initial upline/serial, and it recurses as you want.

Now i'll take a look at your table. Any chance of some sample data?

 

cant put

$sql = "INSERT INTO gptran(GpTID) VALUES($upline)";

into uplinepyramid(); function rite? but why?

thanks

i modified to below code. ..but the array data can echo inside this function,but when i echo after this function then become null. why?

 
<?php
   function uplinepyramid($upline2,$arraycount){
    	echo "<br> enter uplinepyramid function";
    	echo "<br> upline id(variable)=".$upline2;
    	echo "<br> array count=".$arraycount;

    	    $result2=mysql_query("SELECT * from gamecard ORDER BY Serial");
    	    
    
    	   	while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){//finding match upline
    	   		
    	      	if($row2[serialnum]==$upline2){
    	      		echo "</br>upline id(row)=".$row2[serialnum];
    	      		
    	      		$upline3=$row2[upline];
    	      		$uplinepy[$arraycount]=$row2[serialnum];
    	      		$arraycount+=1;
    	      		echo "</br>array in function=".$uplinepy[$arraycount];
    	      		
    	      		//$sql="INSERT INTO gptran (GpTID)
                   //     VALUES
                   //   ('$_POST[upline]')";
                   //     mysql_query($sql,$con);
    	      		
    	  	      		
    	      		
    	      		
    	      		if(!empty($row2[upline])){// loop this function back
    	      			
    	      			uplinepyramid($upline3,$arraycount);
    	      			
    	      		}//enf if
    	      	}//end if
    	  		
    	  	}//end while
    	
    	
    }//end function
?>

bro, solution found!

mysql_query($sql,$con);

change to

mysql_query($sql);

 

...but why? weird..

 

 

if

mysql_query($sql,$con);

then  occur error msg

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampplite\htdocs\EN\menu\UsrCard\usraddc.php on line 212

 

but why? weird... ???

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.