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
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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

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... ???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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