Jump to content

hang when array amount is large


zgkhoo

Recommended Posts

function new_order($a){
$out = array();
$n = count($a) / 2;
foreach ($a as $k => $v){
	$m = $n;
	$newk = 0;
	while ($k > 0){
		$newk += ($k % 2) * $m;
		$k = (int) $k / 2;
		$m = $m / 2;
	}
	$out[$newk] = $v;
}
ksort($out);
return $out;
}

when the array is huge.eg 1024 or 2048 or above binary amount of array..

then my pc..hang .....my processor usage going to 100%..

any solution?? :-\

 

Link to comment
Share on other sites

1) You can modify the script to deal with less data, or at least handle it more efficiently memory-wise.

how for the above script? as i cant minus the array amount.. ??? ??? headace

how many GB memory required? 4GB?

i just test it on my own then already hang...wat if 20 ppl log in and use the above function?

oh my god..really cant think any solution... :-\ :-\

Link to comment
Share on other sites

<?php
include 'config.php';
include 'opendb.php';





//insert gamecard initial into pyramidass table
//echo "<select name=initial>";
$result=mysql_query("SELECT DISTINCT Initial from gamecard ORDER BY Initial");



while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
$existing=0;


//echo "<option value=$row[initial] selected='selected'>$row[initial]</option>";
$ID=findid();	
//echo "</br>id=".$ID;

          $result2=mysql_query("SELECT * from pyramidass");
          while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
         	if($row2[initial]==$row[initial]){
	     	$existing=1;
	     //	echo "</br>exiting!";
         	}
           	}

if($existing!=1&&!empty($row[initial])){


$sql="INSERT INTO pyramidass(ID,Initial,AssoTable)
 VALUES
('$ID','$row[initial]','prymain')";
mysql_query($sql);
}




}
// "</br>existing=".$existing;



//echo "</select>";
//echo "</form>";



//display the pyramidass table record into a selected box

$result=mysql_query("SELECT * from pyramidass ORDER BY ID");


echo "<form action='testing6.php' method='POST'>";
echo "<font>Select The Initial(gamecard) For Check</font>";
echo "<select name=serialini>";


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	echo "<option value=$row[initial] selected='selected'>$row[iD]  $row[initial]</option>";


}

echo "</select>";
echo "<input type=submit name=check value=check></input>";
echo "</form>";



//for rate checking
$result=mysql_query("SELECT * from rate ORDER BY RID");


echo "<form action='testing6.php' method='POST'>";
echo "<font>Select The rate For Check</font>";
echo "<select name=ratename>";


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	echo "<option value=$row[RateName] selected='selected'>$row[RID]  $row[RateName]</option>";


}

echo "</select>";
echo "<input type=submit name=check2 value=check></input>";
echo "</form>";





//
if(isset($_POST['button3'])){


//create pyramidass table
$sql = "CREATE TABLE rate
	    (
		RID integer(10),
		RateName varchar(10),
		Rate decimal(6,2),
		Primary Key(RID)			 
		)";

mysql_query($sql);

$ID=findrateID();

$sql="INSERT INTO rate(RID,RateName,Rate)
 VALUES
('$ID','SELL','20')";

mysql_query($sql);

$ID=findrateID();

//$sql="INSERT INTO rate(RID,RateName,Rate)
// VALUES
//('$ID','ACTIVATE','100')";

//mysql_query($sql);

$ID=findrateID();

$sql="INSERT INTO rate(RID,RateName,Rate)
 VALUES
('$ID','PYRAMID','10')";

mysql_query($sql);

$ID=findrateID();

$sql="INSERT INTO rate(RID,RateName,Rate)
 VALUES
('$ID','GP2CP','100')";

mysql_query($sql);



}



//if create table button clicked
if(isset($_POST['button'])){
$new_table = $_POST['tablename'];
$sql = "CREATE TABLE $new_table


		(
		PID integer(10),
		Serialnum varchar(10),
		UplineSerial varchar(10),
		UplinePID integer(10),
		Downleft integer(10),
		LeftSerial varchar(10),
		Downright integer(10),
		RightSerial varchar(10),
		RowNum integer(10),
		ColumnPosi integer(10),
		ColumnTotal integer(10),
		DownlineAmount integer(10),
		Initial varchar(10),
		ActivateTime datetime,
		Status varchar(10),
		UserID varchar(10),
		ExpiredDate datetime,
		CreateDate datetime,
		Golden varchar(10),

		Primary Key (PID)     	    
		)";
		mysql_query($sql);

		$ID=findpyramidTID();

		$sql="INSERT INTO pyramidT(TID,TableName)
               VALUES
             ('$ID','$new_table')";
        mysql_query($sql);
}




if(isset($_POST['button2'])){

//create pyramidass table
$sql = "CREATE TABLE pyramidass
	    (
		ID integer(10),
		Initial varchar(10),
		AssoTable varchar(10),
		Primary Key(ID)

		)";

mysql_query($sql);

//insert default pyramid-pyrmain for else cards.
$ID=findid();
$sql="INSERT INTO pyramidass(ID,Initial,AssoTable)
 VALUES
 ('$ID','Else','prymain')";
 mysql_query($sql);



//create pyramidT table

$sql = "CREATE TABLE pyramidT


		(
		TID integer(10),
		TableName varchar(10),
	    Primary Key(TID)			
      	    
		)";
		mysql_query($sql);



//create a default pyramid table
$sql = "CREATE TABLE pyrmain


		(
		PID integer(10),
		Serialnum varchar(10),
		UplineSerial varchar(10),
		UplinePID integer(10),
		Downleft integer(10),
		LeftSerial varchar(10),
		Downright integer(10),
		RightSerial varchar(10),
		RowNum integer(10),
		ColumnPosi integer(10),
		ColumnTotal integer(10),
		DownlineAmount integer(10),
		Initial varchar(10),
		ActivateTime datetime,
		Status varchar(10),
		UserID varchar(10),
		ExpiredDate datetime,
		CreateDate datetime,
		Golden varchar(10),

		Primary Key (PID)    	    
		)";
		mysql_query($sql);

		$ID=findpyramidTID();

//insert the default pyrmain table into pyramidT
		$sql="INSERT INTO pyramidT(TID,TableName)
               VALUES
             ('$ID','pyrmain')";
        mysql_query($sql);
}



//if check initial asso button is clicked
if(isset($_POST['check'])){
 	//echo "</br>post =".$_POST['serialini'];



$result = mysql_query("SELECT * FROM pyramidass ") or die('Query failed: ' . mysql_error());
   
echo "<form action=testing6.php method=post>"; 
echo "<table>";
echo "<tr>";

   



	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

               if ($_POST['serialini']==$row['Initial']){
               //	echo "</br>post =".$_POST['serialini'];
               //	echo "</br>row=".$row['Initial'];
               	
               // echo "</br>".$row['ID'].$row['Initial'].$row['AssoTable'];	
                echo " 
                <tr>
                <td>ID</td>
                <td><input type='text' name='id'  value=$row[iD] readonly></td>
                </tr>
                <tr>
                <td>Initial</td>
                <td><input type='text' name='initial'  value=$row[initial] readonly></td>
                </tr>
                <tr>
                <td>Associated Table</td>
                <td><select name=assotable>";
                $result2 = mysql_query("SELECT * FROM pyramidT") or die('Query failed: ' . mysql_error());
                while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
                 //echo"<td><input type='text' name='assotable'  value=$row2[AssoTable]></td>";
                 //echo "<option value=$row[AssoTable] selected='selected'>$row[AssoTable]</option>";
                 if($row[AssoTable]==$row2[TableName]){
                 echo "<option value=$row2[TableName] selected='selected'>$row2[TableName]</option>";
                 }
                 else{
                 	echo "<option value=$row2[TableName]>$row2[TableName]</option>";                 	
                 }
                 
                 }//end while
                 echo "</select>";
                 echo "</td>";
               
                echo "</tr>";
               }//end if


                    

         }//end while

echo "<tr><td><input type=submit name=change value=change></td></tr>";
echo "</table>";
echo "</form>";
}




if(isset($_POST['check2'])){
 	//echo "</br>post =".$_POST['serialini'];



$result = mysql_query("SELECT * FROM rate ") or die('Query failed: ' . mysql_error());
   
echo "<form action=testing6.php method=post>"; 
echo "<table>";
echo "<tr>";

   



	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

               if ($_POST['ratename']==$row['RateName']){
               //	echo "</br>post =".$_POST['serialini'];
               //	echo "</br>row=".$row['Initial'];
               	
               // echo "</br>".$row['ID'].$row['Initial'].$row['AssoTable'];	
                echo " 
                <tr>
                <td>ID</td>
                <td><input type='text' name='rid'  value=$row[RID] readonly></td>
                </tr>
                <tr>
                <td>Initial</td>
                <td><input type='text' name='initial'  value=$row[RateName] readonly></td>
                </tr>
                <tr>
                <td>Rate</td>
                <td><input type='text' name='rate'  value=$row[Rate]></td>
                <!--<td><select name=rateamount>-->";
               // $result2 = mysql_query("SELECT * FROM rate ORDER BY RID") or die('Query failed: ' . mysql_error());
               // while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
                 //echo"<td><input type='text' name='assotable'  value=$row2[AssoTable]></td>";
                 //echo "<option value=$row[AssoTable] selected='selected'>$row[AssoTable]</option>";
                // if($row[Rate]==$row2[Rate]){
                 //echo "<option value=$row2[Rate] selected='selected'>$row2[Rate]</option>";
                // }
                // else{
                // 	echo "<option value=$row2[Rate]>$row2[Rate]</option>";                 	
               //  }
                 
                 }//end while
             //   echo "</select>";
               
                echo "</tr>";
               //}//end if


                    

         }//end while

echo "<tr><td><input type=submit name=changerate value=changerate></td></tr>";
echo "</table>";
echo "</form>";
}



if(isset($_POST['change'])){

                    mysql_query("UPDATE pyramidass SET AssoTable = '$_POST[assotable]' 
                    where ID='$_POST[id]'");
}


if(isset($_POST['changerate'])){

                    mysql_query("UPDATE rate SET Rate = '$_POST[rate]' 
                    where RID='$_POST[rid]'");
}






function findid(){
$result=mysql_query("SELECT * from pyramidass ORDER BY ID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $ID=$row[iD];


     }//end while
     
return $ID+1;	

    }//end else
}


function findrateID(){
$result=mysql_query("SELECT * from rate ORDER BY RID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $ID=$row[RID];


     }//end while
     
return $ID+1;	

    }//end else
}



function findpyramidTID(){
$result=mysql_query("SELECT * from pyramidT ORDER BY TID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $id=$row[GpTID];


     }//end while
     
return $id+1;	

    }//end else
}




//insert admin card module!!!!!!!!!!!!!

if(isset($_POST['insertadmincard'])){
//store admin card into gamecard table
	$result=mysql_query("SELECT * from rate ORDER BY RID");


	//while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	for($i=0,$count=$_POST['admincardnum'];$i<$count;$i++) {
	$ID="AAA".$i;
	$sql="INSERT INTO gamecard(Serialnum,Serial,Ownerid)
              VALUES
    ('$ID','$i','AdminCard')";
	mysql_query($sql);

	//$pyrtable=findpyramid($ID);
	$prytable=$_POST['assotable'];
	echo "</br>prytable=".$_POST['assotable'];

	addpyramidcard($ID,$_POST['assotable']);
    	  		    
    	//setpyramidbonus($row[serialnum],$pyrtable);


	}

		     



}







//start into pyramid module!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//start into pyramid module!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//start into pyramid module!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//insert into pyramid module...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



function addpyramidcard($cardID,$pyrtable){   
//global $pyrtable; 


echo "</br><font color=red>cardID to add in pyramid=</font>".$cardID;
echo "</br>Pyramid table to save=".$pyrtable;
//find the lastpid in dbstore
$lastID=findlastPID($pyrtable);
//find the lastrownum for pyramid in dbstore
$lastRowNum=findlastRowNum($pyrtable);
//find the lastcolumntotal for latest row for pyramid in dbstore
$lastColumnTotal=findlastColumnTotal($pyrtable);



//calculate the current rows's limit


//display all three variable
echo "</br><font color=red>PID to be save=</font>".$lastID;
echo "</br>lastrownum(Row's element limit)=".$lastRowNum;
echo "</br>lastcolumnTotal(last column posi)=".$lastColumnTotal;
//echo "</br>Pyramid table status=".checkpyramidlastrow($pyrtable);

//if columntotal is less than row limit
if($lastColumnTotal<$lastRowNum)
{
echo "</br></br><font color=red>enter first(pyramid not full)</font>";
//updatelastColumnTotal();
//$lastColumnTotal=findlastColumnTotal();
$Columnposi=findColumnPosi($lastRowNum,$pyrtable);
$uplineid=findupline($Columnposi,$lastRowNum,$lastID,$cardID,$pyrtable);
$uplineSerial=finduplineserial($Columnposi,$lastRowNum,$lastID,$pyrtable);
echo "</br>Pyramid UPLINE CARD ID=".$uplineid;
echo "</br>Pyramid UPLINE Serial=".$uplineSerial;
echo "</br><font color=red>RowNum to be save=</font>".$lastRowNum;
echo "</br><font color=red>Column position to save=</font>".$Columnposi;

    $userID=findcarduser($cardID);


$sql="INSERT INTO $pyrtable(PID,Serialnum,RowNum,ColumnPosi,UplineSerial,UplinePID,UserID)
      VALUES
    ('$lastID','$cardID','$lastRowNum','$Columnposi','$uplineSerial','$uplineid','$userID')";
    mysql_query($sql);
    
   // updatelastPID();



}//end if

//if the columntotal is equal with the rowlimit

//if columntotal is reach the row limit
else{
echo "</br>enter second(pyramid full)";
//resetlastColumnTotal();
//updatelastColumnTotal();
//updatelastRowNum();
$lastRowNum=findlastRowNum($pyrtable);   
$lastRowNum=$lastRowNum*2;
$lastColumnTotal=0;
$Columnposi=findColumnPosi($lastRowNum,$pyrtable);
$uplineid=findupline($Columnposi,$lastRowNum,$lastID,$cardID,$pyrtable);
$uplineSerial=finduplineserial($Columnposi,$lastRowNum,$lastID,$pyrtable);

echo "</br>Pyramid UPLINE CARD ID=".$uplineid;
echo "</br>Pyramid UPLINE Serial=".$uplineSerial;
echo "</br>RowNum to be save=".$lastRowNum;
echo "</br>Column position to save=".$Columnposi;

$userID=findcarduser($cardID);
$sql="INSERT INTO $pyrtable(PID,Serialnum,RowNum,ColumnPosi,UplineSerial,UplinePID,UserID)
      VALUES
    ('$lastID','$cardID','$lastRowNum','$Columnposi','$uplineSerial','$uplineid','$userID')";
    mysql_query($sql);


   // updatelastPID();


}//end else



}//end function


function lastGpTID(){ 

$result=mysql_query("SELECT * from gptran ORDER BY GpTID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $Gptid=$row[GpTID];


     }//end while
     
return $Gptid+1;	

    }//end else
}






//find the last pid 
function findlastPID($pyrtable)
{
$pyrtable;
$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
if(mysql_num_rows($result)==0){
	return 1001;
}
else{


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$pid=$row[PID];


}//end while
return $pid+1;

    }//end else
}//end function 




//find the lastrownum 
function findlastRowNum($pyrtable)
{

//echo "</br>enter findlastRowNum()";

$result=mysql_query("SELECT from $pyrtable ORDER BY PID");

if(mysql_num_rows($result)==0){
	return 1;
}//end if

else{
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$rownum=$row[RowNum];


}
return $rownum;
}

}



//find the last columntotal 
function findlastColumnTotal($pyrtable)
{

$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
//echo "</br>enter findlastColumnTotal()";
if(mysql_num_rows($result)==0){
	return 0;
}//end if
else{


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$columnposi=$row[ColumnPosi];


}
return $columnposi;
}

}



function findColumnPosi($lastRowNum,$pyrtable){ //find which column position number for record to save
//echo "</br>enter findColumnPosi()";
//echo "</br>last row num=".$lastRowNum;



for($i=0;$i<=$lastRowNum-1;$i++){
	$a[$i] = $i+1;

}
//print_r($a);

//echo "</br>new array=</br>";


    $b = new_order($a);
    
  //  print "<PRE>";
  //  print_r($b);
//   print "</PRE>";
    
    
    //find the current blank position for the same rownum
    

    
    
    for($i=0;$i<=$lastRowNum-1;$i++){
    //	echo "</br><font color=red>enter for loop i=</font>".$b[$i];
    	
    	
    	   $result=mysql_query("SELECT * from $pyrtable WHERE RowNum=$lastRowNum");
    	   
    	   $found=0;

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
  //	echo "<br>while loop column num in DB=".$row[ColumnPosi];

	//echo "</br>with Array=".$b[$i];
	if($row[ColumnPosi]==$b[$i])//if column num already got the record
	{
		$found=1;	

	}//end if
	else{  

	}//end else

}//end while
	if($found==1){

	//echo "</br>found=======================".$b[$i];
	}
	else{
//		echo "</br>save in=======================".$b[$i];
		return $b[$i];

	}

}//end of for loop
}


//function for calculate the new columnposi number for the new card
function new_order($a){
$out = array();
$n = count($a) / 2;
foreach ($a as $k => $v){
	$m = $n;
	$newk = 0;
	while ($k > 0){
		$newk += ($k % 2) * $m;
		$k = (int) $k / 2;
		$m = $m / 2;
	}
	$out[$newk] = $v;
}
ksort($out);
return $out;
}


function findupline($downline,$rowtotal,$downlineID,$cardID,$pyrtable){

$upline=round($downline/2);
$uprow=$rowtotal/2;
echo "</br></font color=green>upline(pyramid)'s Column Posi=</font>".$upline;
echo "</br></font color=green>upline(pyramid)'s RowNum=</font>".$uprow;



$result=mysql_query("SELECT * from $pyrtable WHERE RowNum=$uprow");

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	if($row[ColumnPosi]==$upline){
		 if($downline/2!=$upline){
		 mysql_query("UPDATE $pyrtable SET Downleft= '$downlineID',LeftSerial='$cardID' WHERE PID = '$row[PID]'") or die(mysql_error());
		 }
		 else{
		 mysql_query("UPDATE $pyrtable SET Downright= '$downlineID',RightSerial='$cardID' WHERE PID = '$row[PID]'") or die(mysql_error());

		 }
	echo "</br>upline(pyramid)[PID]=".$row[PID];
	return $row[PID];
	}
}


}


function setpyramidbonus($cardID,$pyrtable){

echo "</br>enter set pyramid bonus";
$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	if($row[serialnum]==$cardID){
		echo "</br>row upline=".$row[uplineSerial];
		$levelcount=1;

		loopupline($row[uplineSerial],$levelcount,$cardID,$pyrtable);
	}

}



}



function loopupline($upline2,$levelcount,$cardserial2,$pyrtable)
{

echo "</br></br>";
echo "</br><font color=purple>Enter loop(pyramid upline bonus) function</font>";
//echo "</br>upline2=".$upline2;
echo "</br>Level Count=".$levelcount;
$rate=findrate('PYRAMID');
//echo "</br>pyramid rate=".$rate;

  //  if($levelcount==1){
    //	$cardserial2=$upline2;
    //	}
    	 $result2=mysql_query("SELECT * from $pyrtable ORDER BY PID");
    	 while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
    	 	if($row2[serialnum]==$upline2){
    	 		
    	 		
    	 		

    	 	echo "</br><font color=green>start searching upline record in pyramid</font>";
    	 	//echo "</br>upline2=".$upline2;
    	 	echo "</br><font color=red>Serialnum=</font>".$row2[serialnum];
    	 	$lastID=lastGpTID();
    	 	$userID=findcarduser($upline2);
    	 	echo "</br>userid=".$userID;

    	 	
    	 	
    	 	
    	 	$sql="INSERT INTO gptran (GpTID,TranDate,Mode,CardSerial,BenefitFrom,BenefitFlevel,TranPoint,Purpose,FromWhere,ToWhere,UserID)
                        VALUES
            ('$lastID',NOW(),'Credit','$row2[serialnum]','$cardserial2','$levelcount','$rate','PRYRAMID BONUS','CompanyPoint','UserPoint','$userID')";
                         mysql_query($sql);
            //$lastID+=1;
    	   // mysql_query("UPDATE dbstore SET LastGpTID='$lastID'") or die(mysql_error());//increase gptid

    	 	
     	 	
		    	 	if($upline2!='0'&&$levelcount<11){
		    	 		$upline2=$row2[uplineSerial];
		    	 		$levelcount=$levelcount+1;
		    	 		echo "</br><font color=blue>upline serialnum to be loop=</font>".$upline2;
		    	 		//echo "</br><font color=blue>upline serial before loop=</font>".$row2[uplineSerial];
		    	 		
		    	 		loopupline($upline2,$levelcount,$cardserial2,$pyrtable);
		    	 		
		    	 	}//end if
    	 	}
    	    if($upline2=='0'){
    	 		
    	 	echo "</br><font color=red>end</font>";
    	 		
    	 	}//end if	
    	 	
    	 	
    	 	
    	 }//end while
}//end function

function finduplineserial($downline,$rowtotal,$downlineID,$pyrtable){

$upline=round($downline/2);
$uprow=$rowtotal/2;

//echo "</br>upline column posi".$upline;
//echo "</br>upline row=".$uprow;

$result=mysql_query("SELECT * from $pyrtable WHERE RowNum=$uprow");

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	if($row[ColumnPosi]==$upline){

	return $row[serialnum];
	}
}


}

function setsellcardbonus($upline,$downline){

    	$lastID=lastGpTID();
    	$userID=findcarduser($upline);
    	$rate=findrate('SELL');
    	//echo "sell rate=".$rate;
    	
    	 	
    	 	$sql="INSERT INTO gptran (GpTID,UserID,TranDate,Mode,CardSerial,BenefitFrom,BenefitFlevel,TranPoint,Purpose,FromWhere,ToWhere)
                        VALUES
            ('$lastID','$userID',NOW(),'Credit','$upline','$downline','1',$rate,'SELL CARD','CompanyPoint','UserPoint')";
                         mysql_query($sql);
           // $lastID+=1;
    	   // mysql_query("UPDATE dbstore SET LastGpTID='$lastID'") or die(mysql_error());//increase gptid

}


function setbuycardbonus($cardID){

	    $lastID=lastGpTID();
	    $userID=findcarduser($cardID);
	    $rate=findcardpoint($cardID);
	    
	    //echo "activate card rate=".$rate;
    	 	
    	 	$sql="INSERT INTO gptran (GpTID,UserID,TranDate,Mode,CardSerial,BenefitFrom,BenefitFlevel,TranPoint,Purpose,FromWhere,ToWhere)
                        VALUES
            ('$lastID','$userID',NOW(),'Credit','$cardID','$cardID','1',$rate,'ACTIVATE CARD','CompanyPoint','UserPoint')";
                         mysql_query($sql);
            $lastID+=1;
    	    mysql_query("UPDATE dbstore SET LastGpTID='$lastID'") or die(mysql_error());//increase gptid


}

function findpyramid($cardID){
    
    //find initial
    $result=mysql_query("SELECT * from gamecard ORDER BY Serial");
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
    	if($row[serialnum]==$cardID){
    		$initial=$row[initial];
    	}
    	
    }
    
    if(empty($initial)){
    	$initial='Else';
    }
    
    


	$result2=mysql_query("SELECT * from pyramidass ORDER BY ID");
	while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
		if($row2[initial]==$initial){
			return $row2[AssoTable];
		}//end if

	}//end while





}//function


function findcarduser($ID){
//echo "</br>enter find car user";
$result=mysql_query("SELECT * from gamecard ORDER BY Serial");
	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
		if($row[serialnum]==$ID){
			//echo "</br>valid find card user";
			//echo "</br>UserID for this card=".$row[Ownerid];
			return $row[Ownerid];
		}

	}




}


function checkpyramidlastrow($pyrtable){


	$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
		if(mysql_num_rows($result)==0){
			return "blank";

		}
		else{

			while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
				if($row[RowNum]==$row[ColumnPosi]){
					$status="full";
				}
				else{
					$status="notfull";
				}

			}
			return $status;
		}

}


function findrate($mode){
$result=mysql_query("SELECT * from rate ORDER BY RID");

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	if($row[RateName]==$mode){
		return $row[Rate];
	}

}




}

function findcardpoint($cardID){
$result=mysql_query("SELECT * from gamecard ORDER BY Serial");

	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	if($row[serialnum]==$cardID){
		return $row[Point];
	}

}

}




include 'closedb.php';







?>



<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head> 
<form name='createtable' action='testing6.php' method=post>
<table border="3">
<tr>
<td>new pyramid table name</td>
<td><input type="text" name=tablename><td>
</tr>
<tr>
<td><input type="submit" name='button' value='create'><td>
</tr>
<tr>
<td><input type="submit" name='button2' value='create pyramid table list'><td>
</tr>
<tr>
<td><input type="submit" name='button3' value='create rate '><td>
</tr>
</table>
</form>

<form name='insertadmincard' action='testing6.php' method=post>
<table border="3">
<tr>
<td>Number of Admin card to be insert into pyramid</td>
<td><input type="text" name=admincardnum></td>
</tr>
<tr>
<td>Select which pyramid table to be insert</td>


                <td><select name=assotable>
                <?php
                include 'config.php';
                include 'opendb.php';
                
                $result2 = mysql_query("SELECT * FROM pyramidT") or die('Query failed: ' . mysql_error());
                while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){

                 if($row[AssoTable]==$row2[TableName]){
                 echo "<option value=$row2[TableName] selected='selected'>$row2[TableName]</option>";
                 }//end if
                 else{
                 	echo "<option value=$row2[TableName]>$row2[TableName]</option>";                 	
                 }//end else
                                  
                 }//end while
                 include 'closedb.php';
                 ?>
                 </select>
                 </td>
</tr>
<tr>

<td><input type="submit" name='insertadmincard' value='insert'><td>
</tr>
</table>
</form>


</html>

 

the page that cause the lag n lag n lag....any problem with the above page?

thanks

Link to comment
Share on other sites

<?php
include 'config.php';
include 'opendb.php';





//insert gamecard initial into pyramidass table
//echo "<select name=initial>";
$result=mysql_query("SELECT DISTINCT Initial from gamecard ORDER BY Initial");



while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
$existing=0;


//echo "<option value=$row[initial] selected='selected'>$row[initial]</option>";
$ID=findid();	
//echo "</br>id=".$ID;

          $result2=mysql_query("SELECT * from pyramidass");
          while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
         	if($row2[initial]==$row[initial]){
	     	$existing=1;
	     //	echo "</br>exiting!";
         	}
           	}

if($existing!=1&&!empty($row[initial])){


$sql="INSERT INTO pyramidass(ID,Initial,AssoTable)
 VALUES
('$ID','$row[initial]','prymain')";
mysql_query($sql);
}




}
// "</br>existing=".$existing;



//echo "</select>";
//echo "</form>";



//display the pyramidass table record into a selected box

$result=mysql_query("SELECT * from pyramidass ORDER BY ID");


echo "<form action='testing6.php' method='POST'>";
echo "<font>Select The Initial(gamecard) For Check</font>";
echo "<select name=serialini>";


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	echo "<option value=$row[initial] selected='selected'>$row[iD]  $row[initial]</option>";


}

echo "</select>";
echo "<input type=submit name=check value=check></input>";
echo "</form>";



//for rate checking
$result=mysql_query("SELECT * from rate ORDER BY RID");


echo "<form action='testing6.php' method='POST'>";
echo "<font>Select The rate For Check</font>";
echo "<select name=ratename>";


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	echo "<option value=$row[RateName] selected='selected'>$row[RID]  $row[RateName]</option>";


}

echo "</select>";
echo "<input type=submit name=check2 value=check></input>";
echo "</form>";





//
if(isset($_POST['button3'])){


//create pyramidass table
$sql = "CREATE TABLE rate
	    (
		RID integer(10),
		RateName varchar(10),
		Rate decimal(6,2),
		Primary Key(RID)			 
		)";

mysql_query($sql);

$ID=findrateID();

$sql="INSERT INTO rate(RID,RateName,Rate)
 VALUES
('$ID','SELL','20')";

mysql_query($sql);

$ID=findrateID();

//$sql="INSERT INTO rate(RID,RateName,Rate)
// VALUES
//('$ID','ACTIVATE','100')";

//mysql_query($sql);

$ID=findrateID();

$sql="INSERT INTO rate(RID,RateName,Rate)
 VALUES
('$ID','PYRAMID','10')";

mysql_query($sql);

$ID=findrateID();

$sql="INSERT INTO rate(RID,RateName,Rate)
 VALUES
('$ID','GP2CP','100')";

mysql_query($sql);



}



//if create table button clicked
if(isset($_POST['button'])){
$new_table = $_POST['tablename'];
$sql = "CREATE TABLE $new_table


		(
		PID integer(10),
		Serialnum varchar(10),
		UplineSerial varchar(10),
		UplinePID integer(10),
		Downleft integer(10),
		LeftSerial varchar(10),
		Downright integer(10),
		RightSerial varchar(10),
		RowNum integer(10),
		ColumnPosi integer(10),
		ColumnTotal integer(10),
		DownlineAmount integer(10),
		Initial varchar(10),
		ActivateTime datetime,
		Status varchar(10),
		UserID varchar(10),
		ExpiredDate datetime,
		CreateDate datetime,
		Golden varchar(10),

		Primary Key (PID)     	    
		)";
		mysql_query($sql);

		$ID=findpyramidTID();

		$sql="INSERT INTO pyramidT(TID,TableName)
               VALUES
             ('$ID','$new_table')";
        mysql_query($sql);
}




if(isset($_POST['button2'])){

//create pyramidass table
$sql = "CREATE TABLE pyramidass
	    (
		ID integer(10),
		Initial varchar(10),
		AssoTable varchar(10),
		Primary Key(ID)

		)";

mysql_query($sql);

//insert default pyramid-pyrmain for else cards.
$ID=findid();
$sql="INSERT INTO pyramidass(ID,Initial,AssoTable)
 VALUES
 ('$ID','Else','prymain')";
 mysql_query($sql);



//create pyramidT table

$sql = "CREATE TABLE pyramidT


		(
		TID integer(10),
		TableName varchar(10),
	    Primary Key(TID)			
      	    
		)";
		mysql_query($sql);



//create a default pyramid table
$sql = "CREATE TABLE pyrmain


		(
		PID integer(10),
		Serialnum varchar(10),
		UplineSerial varchar(10),
		UplinePID integer(10),
		Downleft integer(10),
		LeftSerial varchar(10),
		Downright integer(10),
		RightSerial varchar(10),
		RowNum integer(10),
		ColumnPosi integer(10),
		ColumnTotal integer(10),
		DownlineAmount integer(10),
		Initial varchar(10),
		ActivateTime datetime,
		Status varchar(10),
		UserID varchar(10),
		ExpiredDate datetime,
		CreateDate datetime,
		Golden varchar(10),

		Primary Key (PID)    	    
		)";
		mysql_query($sql);

		$ID=findpyramidTID();

//insert the default pyrmain table into pyramidT
		$sql="INSERT INTO pyramidT(TID,TableName)
               VALUES
             ('$ID','pyrmain')";
        mysql_query($sql);
}



//if check initial asso button is clicked
if(isset($_POST['check'])){
 	//echo "</br>post =".$_POST['serialini'];



$result = mysql_query("SELECT * FROM pyramidass ") or die('Query failed: ' . mysql_error());
   
echo "<form action=testing6.php method=post>"; 
echo "<table>";
echo "<tr>";

   



	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

               if ($_POST['serialini']==$row['Initial']){
               //	echo "</br>post =".$_POST['serialini'];
               //	echo "</br>row=".$row['Initial'];
               	
               // echo "</br>".$row['ID'].$row['Initial'].$row['AssoTable'];	
                echo " 
                <tr>
                <td>ID</td>
                <td><input type='text' name='id'  value=$row[iD] readonly></td>
                </tr>
                <tr>
                <td>Initial</td>
                <td><input type='text' name='initial'  value=$row[initial] readonly></td>
                </tr>
                <tr>
                <td>Associated Table</td>
                <td><select name=assotable>";
                $result2 = mysql_query("SELECT * FROM pyramidT") or die('Query failed: ' . mysql_error());
                while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
                 //echo"<td><input type='text' name='assotable'  value=$row2[AssoTable]></td>";
                 //echo "<option value=$row[AssoTable] selected='selected'>$row[AssoTable]</option>";
                 if($row[AssoTable]==$row2[TableName]){
                 echo "<option value=$row2[TableName] selected='selected'>$row2[TableName]</option>";
                 }
                 else{
                 	echo "<option value=$row2[TableName]>$row2[TableName]</option>";                 	
                 }
                 
                 }//end while
                 echo "</select>";
                 echo "</td>";
               
                echo "</tr>";
               }//end if


                    

         }//end while

echo "<tr><td><input type=submit name=change value=change></td></tr>";
echo "</table>";
echo "</form>";
}




if(isset($_POST['check2'])){
 	//echo "</br>post =".$_POST['serialini'];



$result = mysql_query("SELECT * FROM rate ") or die('Query failed: ' . mysql_error());
   
echo "<form action=testing6.php method=post>"; 
echo "<table>";
echo "<tr>";

   



	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

               if ($_POST['ratename']==$row['RateName']){
               //	echo "</br>post =".$_POST['serialini'];
               //	echo "</br>row=".$row['Initial'];
               	
               // echo "</br>".$row['ID'].$row['Initial'].$row['AssoTable'];	
                echo " 
                <tr>
                <td>ID</td>
                <td><input type='text' name='rid'  value=$row[RID] readonly></td>
                </tr>
                <tr>
                <td>Initial</td>
                <td><input type='text' name='initial'  value=$row[RateName] readonly></td>
                </tr>
                <tr>
                <td>Rate</td>
                <td><input type='text' name='rate'  value=$row[Rate]></td>
                <!--<td><select name=rateamount>-->";
               // $result2 = mysql_query("SELECT * FROM rate ORDER BY RID") or die('Query failed: ' . mysql_error());
               // while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
                 //echo"<td><input type='text' name='assotable'  value=$row2[AssoTable]></td>";
                 //echo "<option value=$row[AssoTable] selected='selected'>$row[AssoTable]</option>";
                // if($row[Rate]==$row2[Rate]){
                 //echo "<option value=$row2[Rate] selected='selected'>$row2[Rate]</option>";
                // }
                // else{
                // 	echo "<option value=$row2[Rate]>$row2[Rate]</option>";                 	
               //  }
                 
                 }//end while
             //   echo "</select>";
               
                echo "</tr>";
               //}//end if


                    

         }//end while

echo "<tr><td><input type=submit name=changerate value=changerate></td></tr>";
echo "</table>";
echo "</form>";
}



if(isset($_POST['change'])){

                    mysql_query("UPDATE pyramidass SET AssoTable = '$_POST[assotable]' 
                    where ID='$_POST[id]'");
}


if(isset($_POST['changerate'])){

                    mysql_query("UPDATE rate SET Rate = '$_POST[rate]' 
                    where RID='$_POST[rid]'");
}






function findid(){
$result=mysql_query("SELECT * from pyramidass ORDER BY ID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $ID=$row[iD];


     }//end while
     
return $ID+1;	

    }//end else
}


function findrateID(){
$result=mysql_query("SELECT * from rate ORDER BY RID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $ID=$row[RID];


     }//end while
     
return $ID+1;	

    }//end else
}



function findpyramidTID(){
$result=mysql_query("SELECT * from pyramidT ORDER BY TID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $id=$row[GpTID];


     }//end while
     
return $id+1;	

    }//end else
}




//insert admin card module!!!!!!!!!!!!!

if(isset($_POST['insertadmincard'])){
//store admin card into gamecard table
	$result=mysql_query("SELECT * from rate ORDER BY RID");


	//while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	for($i=0,$count=$_POST['admincardnum'];$i<$count;$i++) {
	$ID="AAA".$i;
	$sql="INSERT INTO gamecard(Serialnum,Serial,Ownerid)
              VALUES
    ('$ID','$i','AdminCard')";
	mysql_query($sql);

	//$pyrtable=findpyramid($ID);
	$prytable=$_POST['assotable'];
	echo "</br>prytable=".$_POST['assotable'];

	addpyramidcard($ID,$_POST['assotable']);
    	  		    
    	//setpyramidbonus($row[serialnum],$pyrtable);


	}

		     



}







//start into pyramid module!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//start into pyramid module!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//start into pyramid module!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//insert into pyramid module...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



function addpyramidcard($cardID,$pyrtable){   
//global $pyrtable; 


echo "</br><font color=red>cardID to add in pyramid=</font>".$cardID;
echo "</br>Pyramid table to save=".$pyrtable;
//find the lastpid in dbstore
$lastID=findlastPID($pyrtable);
//find the lastrownum for pyramid in dbstore
$lastRowNum=findlastRowNum($pyrtable);
//find the lastcolumntotal for latest row for pyramid in dbstore
$lastColumnTotal=findlastColumnTotal($pyrtable);



//calculate the current rows's limit


//display all three variable
echo "</br><font color=red>PID to be save=</font>".$lastID;
echo "</br>lastrownum(Row's element limit)=".$lastRowNum;
echo "</br>lastcolumnTotal(last column posi)=".$lastColumnTotal;
//echo "</br>Pyramid table status=".checkpyramidlastrow($pyrtable);

//if columntotal is less than row limit
if($lastColumnTotal<$lastRowNum)
{
echo "</br></br><font color=red>enter first(pyramid not full)</font>";
//updatelastColumnTotal();
//$lastColumnTotal=findlastColumnTotal();
$Columnposi=findColumnPosi($lastRowNum,$pyrtable);
$uplineid=findupline($Columnposi,$lastRowNum,$lastID,$cardID,$pyrtable);
$uplineSerial=finduplineserial($Columnposi,$lastRowNum,$lastID,$pyrtable);
echo "</br>Pyramid UPLINE CARD ID=".$uplineid;
echo "</br>Pyramid UPLINE Serial=".$uplineSerial;
echo "</br><font color=red>RowNum to be save=</font>".$lastRowNum;
echo "</br><font color=red>Column position to save=</font>".$Columnposi;

    $userID=findcarduser($cardID);


$sql="INSERT INTO $pyrtable(PID,Serialnum,RowNum,ColumnPosi,UplineSerial,UplinePID,UserID)
      VALUES
    ('$lastID','$cardID','$lastRowNum','$Columnposi','$uplineSerial','$uplineid','$userID')";
    mysql_query($sql);
    
   // updatelastPID();



}//end if

//if the columntotal is equal with the rowlimit

//if columntotal is reach the row limit
else{
echo "</br>enter second(pyramid full)";
//resetlastColumnTotal();
//updatelastColumnTotal();
//updatelastRowNum();
$lastRowNum=findlastRowNum($pyrtable);   
$lastRowNum=$lastRowNum*2;
$lastColumnTotal=0;
$Columnposi=findColumnPosi($lastRowNum,$pyrtable);
$uplineid=findupline($Columnposi,$lastRowNum,$lastID,$cardID,$pyrtable);
$uplineSerial=finduplineserial($Columnposi,$lastRowNum,$lastID,$pyrtable);

echo "</br>Pyramid UPLINE CARD ID=".$uplineid;
echo "</br>Pyramid UPLINE Serial=".$uplineSerial;
echo "</br>RowNum to be save=".$lastRowNum;
echo "</br>Column position to save=".$Columnposi;

$userID=findcarduser($cardID);
$sql="INSERT INTO $pyrtable(PID,Serialnum,RowNum,ColumnPosi,UplineSerial,UplinePID,UserID)
      VALUES
    ('$lastID','$cardID','$lastRowNum','$Columnposi','$uplineSerial','$uplineid','$userID')";
    mysql_query($sql);


   // updatelastPID();


}//end else



}//end function


function lastGpTID(){ 

$result=mysql_query("SELECT * from gptran ORDER BY GpTID");
if(mysql_num_rows($result)==0){
	return 1001;
}//end if
else{


     while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	      $Gptid=$row[GpTID];


     }//end while
     
return $Gptid+1;	

    }//end else
}






//find the last pid 
function findlastPID($pyrtable)
{
$pyrtable;
$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
if(mysql_num_rows($result)==0){
	return 1001;
}
else{


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$pid=$row[PID];


}//end while
return $pid+1;

    }//end else
}//end function 




//find the lastrownum 
function findlastRowNum($pyrtable)
{

//echo "</br>enter findlastRowNum()";

$result=mysql_query("SELECT from $pyrtable ORDER BY PID");

if(mysql_num_rows($result)==0){
	return 1;
}//end if

else{
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$rownum=$row[RowNum];


}
return $rownum;
}

}



//find the last columntotal 
function findlastColumnTotal($pyrtable)
{

$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
//echo "</br>enter findlastColumnTotal()";
if(mysql_num_rows($result)==0){
	return 0;
}//end if
else{


while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	$columnposi=$row[ColumnPosi];


}
return $columnposi;
}

}



function findColumnPosi($lastRowNum,$pyrtable){ //find which column position number for record to save
//echo "</br>enter findColumnPosi()";
//echo "</br>last row num=".$lastRowNum;



for($i=0;$i<=$lastRowNum-1;$i++){
	$a[$i] = $i+1;

}
//print_r($a);

//echo "</br>new array=</br>";


    $b = new_order($a);
    
  //  print "<PRE>";
  //  print_r($b);
//   print "</PRE>";
    
    
    //find the current blank position for the same rownum
    

    
    
    for($i=0;$i<=$lastRowNum-1;$i++){
    //	echo "</br><font color=red>enter for loop i=</font>".$b[$i];
    	
    	
    	   $result=mysql_query("SELECT * from $pyrtable WHERE RowNum=$lastRowNum");
    	   
    	   $found=0;

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
  //	echo "<br>while loop column num in DB=".$row[ColumnPosi];

	//echo "</br>with Array=".$b[$i];
	if($row[ColumnPosi]==$b[$i])//if column num already got the record
	{
		$found=1;	

	}//end if
	else{  

	}//end else

}//end while
	if($found==1){

	//echo "</br>found=======================".$b[$i];
	}
	else{
//		echo "</br>save in=======================".$b[$i];
		return $b[$i];

	}

}//end of for loop
}


//function for calculate the new columnposi number for the new card
function new_order($a){
$out = array();
$n = count($a) / 2;
foreach ($a as $k => $v){
	$m = $n;
	$newk = 0;
	while ($k > 0){
		$newk += ($k % 2) * $m;
		$k = (int) $k / 2;
		$m = $m / 2;
	}
	$out[$newk] = $v;
}
ksort($out);
return $out;
}


function findupline($downline,$rowtotal,$downlineID,$cardID,$pyrtable){

$upline=round($downline/2);
$uprow=$rowtotal/2;
echo "</br></font color=green>upline(pyramid)'s Column Posi=</font>".$upline;
echo "</br></font color=green>upline(pyramid)'s RowNum=</font>".$uprow;



$result=mysql_query("SELECT * from $pyrtable WHERE RowNum=$uprow");

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	if($row[ColumnPosi]==$upline){
		 if($downline/2!=$upline){
		 mysql_query("UPDATE $pyrtable SET Downleft= '$downlineID',LeftSerial='$cardID' WHERE PID = '$row[PID]'") or die(mysql_error());
		 }
		 else{
		 mysql_query("UPDATE $pyrtable SET Downright= '$downlineID',RightSerial='$cardID' WHERE PID = '$row[PID]'") or die(mysql_error());

		 }
	echo "</br>upline(pyramid)[PID]=".$row[PID];
	return $row[PID];
	}
}


}


function setpyramidbonus($cardID,$pyrtable){

echo "</br>enter set pyramid bonus";
$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	if($row[serialnum]==$cardID){
		echo "</br>row upline=".$row[uplineSerial];
		$levelcount=1;

		loopupline($row[uplineSerial],$levelcount,$cardID,$pyrtable);
	}

}



}



function loopupline($upline2,$levelcount,$cardserial2,$pyrtable)
{

echo "</br></br>";
echo "</br><font color=purple>Enter loop(pyramid upline bonus) function</font>";
//echo "</br>upline2=".$upline2;
echo "</br>Level Count=".$levelcount;
$rate=findrate('PYRAMID');
//echo "</br>pyramid rate=".$rate;

  //  if($levelcount==1){
    //	$cardserial2=$upline2;
    //	}
    	 $result2=mysql_query("SELECT * from $pyrtable ORDER BY PID");
    	 while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
    	 	if($row2[serialnum]==$upline2){
    	 		
    	 		
    	 		

    	 	echo "</br><font color=green>start searching upline record in pyramid</font>";
    	 	//echo "</br>upline2=".$upline2;
    	 	echo "</br><font color=red>Serialnum=</font>".$row2[serialnum];
    	 	$lastID=lastGpTID();
    	 	$userID=findcarduser($upline2);
    	 	echo "</br>userid=".$userID;

    	 	
    	 	
    	 	
    	 	$sql="INSERT INTO gptran (GpTID,TranDate,Mode,CardSerial,BenefitFrom,BenefitFlevel,TranPoint,Purpose,FromWhere,ToWhere,UserID)
                        VALUES
            ('$lastID',NOW(),'Credit','$row2[serialnum]','$cardserial2','$levelcount','$rate','PRYRAMID BONUS','CompanyPoint','UserPoint','$userID')";
                         mysql_query($sql);
            //$lastID+=1;
    	   // mysql_query("UPDATE dbstore SET LastGpTID='$lastID'") or die(mysql_error());//increase gptid

    	 	
     	 	
		    	 	if($upline2!='0'&&$levelcount<11){
		    	 		$upline2=$row2[uplineSerial];
		    	 		$levelcount=$levelcount+1;
		    	 		echo "</br><font color=blue>upline serialnum to be loop=</font>".$upline2;
		    	 		//echo "</br><font color=blue>upline serial before loop=</font>".$row2[uplineSerial];
		    	 		
		    	 		loopupline($upline2,$levelcount,$cardserial2,$pyrtable);
		    	 		
		    	 	}//end if
    	 	}
    	    if($upline2=='0'){
    	 		
    	 	echo "</br><font color=red>end</font>";
    	 		
    	 	}//end if	
    	 	
    	 	
    	 	
    	 }//end while
}//end function

function finduplineserial($downline,$rowtotal,$downlineID,$pyrtable){

$upline=round($downline/2);
$uprow=$rowtotal/2;

//echo "</br>upline column posi".$upline;
//echo "</br>upline row=".$uprow;

$result=mysql_query("SELECT * from $pyrtable WHERE RowNum=$uprow");

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){

	if($row[ColumnPosi]==$upline){

	return $row[serialnum];
	}
}


}

function setsellcardbonus($upline,$downline){

    	$lastID=lastGpTID();
    	$userID=findcarduser($upline);
    	$rate=findrate('SELL');
    	//echo "sell rate=".$rate;
    	
    	 	
    	 	$sql="INSERT INTO gptran (GpTID,UserID,TranDate,Mode,CardSerial,BenefitFrom,BenefitFlevel,TranPoint,Purpose,FromWhere,ToWhere)
                        VALUES
            ('$lastID','$userID',NOW(),'Credit','$upline','$downline','1',$rate,'SELL CARD','CompanyPoint','UserPoint')";
                         mysql_query($sql);
           // $lastID+=1;
    	   // mysql_query("UPDATE dbstore SET LastGpTID='$lastID'") or die(mysql_error());//increase gptid

}


function setbuycardbonus($cardID){

	    $lastID=lastGpTID();
	    $userID=findcarduser($cardID);
	    $rate=findcardpoint($cardID);
	    
	    //echo "activate card rate=".$rate;
    	 	
    	 	$sql="INSERT INTO gptran (GpTID,UserID,TranDate,Mode,CardSerial,BenefitFrom,BenefitFlevel,TranPoint,Purpose,FromWhere,ToWhere)
                        VALUES
            ('$lastID','$userID',NOW(),'Credit','$cardID','$cardID','1',$rate,'ACTIVATE CARD','CompanyPoint','UserPoint')";
                         mysql_query($sql);
            $lastID+=1;
    	    mysql_query("UPDATE dbstore SET LastGpTID='$lastID'") or die(mysql_error());//increase gptid


}

function findpyramid($cardID){
    
    //find initial
    $result=mysql_query("SELECT * from gamecard ORDER BY Serial");
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
    	if($row[serialnum]==$cardID){
    		$initial=$row[initial];
    	}
    	
    }
    
    if(empty($initial)){
    	$initial='Else';
    }
    
    


	$result2=mysql_query("SELECT * from pyramidass ORDER BY ID");
	while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){
		if($row2[initial]==$initial){
			return $row2[AssoTable];
		}//end if

	}//end while





}//function


function findcarduser($ID){
//echo "</br>enter find car user";
$result=mysql_query("SELECT * from gamecard ORDER BY Serial");
	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
		if($row[serialnum]==$ID){
			//echo "</br>valid find card user";
			//echo "</br>UserID for this card=".$row[Ownerid];
			return $row[Ownerid];
		}

	}




}


function checkpyramidlastrow($pyrtable){


	$result=mysql_query("SELECT * from $pyrtable ORDER BY PID");
		if(mysql_num_rows($result)==0){
			return "blank";

		}
		else{

			while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
				if($row[RowNum]==$row[ColumnPosi]){
					$status="full";
				}
				else{
					$status="notfull";
				}

			}
			return $status;
		}

}


function findrate($mode){
$result=mysql_query("SELECT * from rate ORDER BY RID");

while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	if($row[RateName]==$mode){
		return $row[Rate];
	}

}




}

function findcardpoint($cardID){
$result=mysql_query("SELECT * from gamecard ORDER BY Serial");

	while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
	if($row[serialnum]==$cardID){
		return $row[Point];
	}

}

}




include 'closedb.php';







?>



<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head> 
<form name='createtable' action='testing6.php' method=post>
<table border="3">
<tr>
<td>new pyramid table name</td>
<td><input type="text" name=tablename><td>
</tr>
<tr>
<td><input type="submit" name='button' value='create'><td>
</tr>
<tr>
<td><input type="submit" name='button2' value='create pyramid table list'><td>
</tr>
<tr>
<td><input type="submit" name='button3' value='create rate '><td>
</tr>
</table>
</form>

<form name='insertadmincard' action='testing6.php' method=post>
<table border="3">
<tr>
<td>Number of Admin card to be insert into pyramid</td>
<td><input type="text" name=admincardnum></td>
</tr>
<tr>
<td>Select which pyramid table to be insert</td>


                <td><select name=assotable>
                <?php
                include 'config.php';
                include 'opendb.php';
                
                $result2 = mysql_query("SELECT * FROM pyramidT") or die('Query failed: ' . mysql_error());
                while($row2 = mysql_fetch_array($result2,MYSQL_ASSOC)){

                 if($row[AssoTable]==$row2[TableName]){
                 echo "<option value=$row2[TableName] selected='selected'>$row2[TableName]</option>";
                 }//end if
                 else{
                 	echo "<option value=$row2[TableName]>$row2[TableName]</option>";                 	
                 }//end else
                                  
                 }//end while
                 include 'closedb.php';
                 ?>
                 </select>
                 </td>
</tr>
<tr>

<td><input type="submit" name='insertadmincard' value='insert'><td>
</tr>
</table>
</form>


</html>

 

the page that cause the lag n lag n lag....any problem with the above page?

thanks

this file y so slow????

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.