I want to form a custom html table in php from a db query. My sql query is
$query = db_select('taxonomy_term_data','td');
$query->join('drone','dg','dg.tid = td.tid ');
$query->fields('td',array('tid','name'));
$query->fields('dg',array('drone_name'));
$result=$query->execute()->fetchAll();
The data returned by the query looks like:
Drone Name Drone Assigned
Huge DJI
Huge Parrot
Beginner Skydio
Beginner Insitu
Beginner EHANG
$drone_table='<br/>
<table id = width="40%" cellspacing="5" cellpadding="5" border="1" align="center";">
<th>Drone Name</th>
<th>Drones Assigned</th>';
I wrote a for loop statement
foreach ($result as $ts){
$drones_assigned[] = $ts->name;
$drn_name = $ts->drone_name;
$com_arr = implode(",",$drone_assigned);
$drone_table.='<tr>
<td>'.$drn_name.'</td>
<td>'.$com_arr.'</td>
</tr>';
}
This doesnt form the table I want. t forms a table a combination of all the drones assigned and one drone.
I want something like
Drone Name Drone Assigned
Huge DJI, Parrot
Beginner Skydio,Insitu,EHANG
But I am getting
Drone Name Drone Assigned
Beginner DJI, Parrot, Skydio,Insitu,EHANG
Beginnerin the "Drone Name" cell, and all of the assigned drones in the other ones, is that right?