I have this data in my database
My Target is this to display that data in a table like this
I'm able to collect all of those data and display it in my HTML table but the things is I'm getting this.
I'm using array to get the user_id and the user type, and from that user ID i look for buyer, if got buyer under that ID, I display it, vise versa.
below are my code for your reference
$GparentType = $conn->query("SELECT type FROM profile WHERE user_id = '".$user_id."'")->fetch_object()->type;
$ParentDetails = array();
$sql = mysqli_query($conn,"SELECT user_id FROM profile WHERE Buy_From ='$user_id'");
while($resSql = mysqli_fetch_array($sql)){
$ParentDetails[] = $resSql["user_id"];
}
echo "<div id=\"container\" style=\"width:250px;margin:0 auto;\">
<table class=\"table table-responsive table-hover\" border=\"1\">
<tr class=\"info\">
<th style=\"width:20%;\">User</th>
<th style=\"width:10%;\">Name</th>
<!--th>Ordered</th>
<th>Comm. </th>
<th>Nett. </th>
<th>Payout</th>
<th>Balance</th-->
</tr>
<tr class=\"parent success\" data-toggle=\"collapse\" data-target=\"#child\" style=\"cursor:pointer\">
<td>".$user_id."<div style=\"float:right\">[".$GparentType."]</div></td>
<td>".$uname."</td>
<!--td id=\"total_order\"></td>
<td id=\"total_comm\"></td>
<td id=\"total_nett\"></td>
<td id=\"total_payout\"></td>
<td id=\"total_bal\"></td-->
</tr>
<tbody id=\"child\" class=\"collapse\">
";
getChild($ParentDetails);
foreach($ParentDetails as $parent){
$parentType = $conn->query("SELECT type FROM profile WHERE user_id = '".$parent."'")->fetch_object()->type;
if($parentType == 'Retailer'){
$details = array();
$sql = mysqli_query($conn,"SELECT user_id,Buy_From FROM profile WHERE Buy_From ='$parent'");
while($resSql = mysqli_fetch_array($sql)){
$details[] = $resSql["user_id"].",".$resSql["Buy_From"];
}
getChild($details);
}
}
echo "</tbody></table>";
and the function
function getChild($details){
$rate = $_POST['rate'];
include("conf.php");
$conn = mysqli_connect($servername, $username, $password, "supplier");
foreach($details as $newDetails){
$expDetails = explode(",",$newDetails);
$uType = $conn->query("SELECT type FROM profile WHERE user_id = '".$expDetails[0]."'")->fetch_object()->type;
$uName = $conn->query("SELECT name FROM profile WHERE user_id = '".$expDetails[0]."'")->fetch_object()->name;
if($uType == "Retailer"){
echo "
<tr class=\"danger\">
<td>".$expDetails[0]."<div style=\"float:right\">[".$uType."]</div></td>
<td>$uName</td>
</tr>
";
}
else{
echo "
<tr>
<td>".$expDetails[0]."<div style=\"float:right\">[".$uType."]</div></td>
<td>$uName</td>
</tr>
";
}}}
Please Help Me how can I achieve it, Thanks