Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am trying to merge multiple MySQL query results into one single array. I am using
array_merge
function but I am getting null result. I am using the recursive function to fetch the data from the MySQL database . Here is my code.
  <?php

	$level=0;
	 $main_array[0]="";  		 // I want the results stored in this array.			

	function get_recursive_users($memberid,$level){
		
    
			$servername = "localhost";
			$username = "*****";
			$password = "*******";
			$dbName="*******"; 
         

				  $conn1 = new mysqli($servername,$username,$password,$dbName)or die("error 1");

				  $downlinks_query ="select MemberID from legcount where SponsorID='$memberid'"; 
				  $downlinks_res=mysqli_query($conn1,$downlinks_query) or die("error");
				  $level=$level+1;

				 
				  while(list($memberid)=mysqli_fetch_array($downlinks_res))
				  {
					 
					 
					  $downlinks_query123 ="SELECT d1.*, d2.`FullName` AS referral_name FROM detailsofuser d1, detailsofuser d2 WHERE d1.`IDSponsor` = d2.`MemberID` and d1.MemberID='$memberid'"; 
					 
					 $downlinks_res123=mysqli_query($conn1,$downlinks_query123) or die("error");
					  
					  $data = mysqli_fetch_array($downlinks_res123);  // This varibale gets the data from database correctly. 
					  
					   global $main_array;      
					  $main_array=array_merge($main_array, $data);
					  
						get_recursive_users($memberid,$level); 
					
    				
				  }  

	}  


   	 get_recursive_users($memberID,$level);
   var_dump($main_array);
?>


What I have tried:

The output is
Quote:
array(1) { [0]=> string(0) "" }


I have got only the value I have inserted manually. Please help me append all the data in
main_array
variable.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900