convert column to row. is it possible?

convert column to row. is it possible?

holshols Posts: 1Questions: 1Answers: 0

I want to make 2 columns(openday, school_name) into 1 row and print it as a table.

I would like to print it out like a desired table.

Is it possible?

If possible, please explain in detail.

my code is :

<?php
$SQL= "SELECT Concat_ws('\n' openday,'', school_name) AS school_column, supply_name,score  from result ";

$grouped = [];
$columns = [];    
 
$resultObject = $result = mysqli_query($conn, $SQL);
foreach ($resultObject as $row) {
$grouped[$row['supply_name']][$row['school_column']] = $row['score'];
$columns[$row['school_column']] = $row['school_column'];
}
 
sort($columns);
$defaults = array_fill_keys($columns,'-');
array_unshift($columns, 'school_column');
 
?>
 
 <body>
 
<table id="example" class="display" style="width:100%" align="center">
  <thead>
  
<?php
 
  While($result = mysqli_fetch_array($resultObject));
{
    echo "<tr>
     <td>supply_name</td> 
    <td> ".$row['school_column']." </td>
    </tr>";
}
?>
  </thead>
 
<tbody>
 
<?php
 
  While($result = mysqli_fetch_array($resultObject));
{
    echo "<tr>
    <td> ".$row['supply_name']." </td>
    <td> ".$row['score']." </td> 
   
    </tr>";
}
 
?>
</tbody>
</table>
</body>

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    I'm afraid your question is not specific to DataTables. As a PHP / SQL question, you'd be better asking on StackOverflow.

    Allan

This discussion has been closed.