Using php to return GROUP_CONCAT ('column x') values

I am trying to use PHP to return SQL values ​​to an HTML table. I can get each column to fill without problems except the last column,"GROUP _ CONCAT (provision_id)."

Relevant Code:

<?php

global $wpdb;
$wpdb->show_errors();
$contents = $wpdb->get_results( $wpdb->prepare("SELECT salaries.id, name, remaining, contract_value, GROUP_CONCAT( provision_id ) FROM salaries LEFT JOIN contracts ON contracts.id = salaries.id GROUP BY salaries.id"));

 ?>

   [table header stuff...]

<?php 

    foreach ($contents as $content) {
        ?>   
             <tr>
                    <td><?php echo $content->name ?></td>
                    <td><?php echo $content->remaining ?></td>
                    <td><?php echo $content->contract_value ?></td>
                    <td><?php echo $content->GROUP_CONCAT(provision_id) ?></td>

    <?php }; ?>   

            </tr>

A simple echo message $content->provision-iddoes not work either.

+5
source share
2 answers

Use an alias for the column .

GROUP_CONCAT( provision_id ) as pids
...
echo $content->pids
+12
source

If you are loading objects, you must specify the column names, which are identifiers of members of a legal class in PHP (I will contact the manual, although their description of valid variable names is horrible):

SELECT ... GROUP_CONCAT(provision_id) AS provisions
+4

All Articles