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');

<?php > <?php While($result = mysqli_fetch_array($resultObject)); { echo "<tr> supply_name ".$row['school_column']." "; } > <?php While($result = mysqli_fetch_array($resultObject)); { echo "<tr> ".$row['supply_name']." ".$row['score']." "; } >
``` ?>

Answers

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 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.