5

I am trying to use PHP to return SQL values into an HTML table. I am able to get every column to populate without a problem except for 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>

Just echoing $content->provision-id doesn't work either.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Adam
  • 405
  • 1
  • 5
  • 22

2 Answers2

12

Use an alias for the column.

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

VolkerK
  • 95,432
  • 20
  • 163
  • 226
4

If you are fetching into objects, you should give your columns names that are legal class member identifiers in PHP (I'll link to the manual, although their description of valid variable names is horrible):

SELECT ... GROUP_CONCAT(provision_id) AS provisions
soulmerge
  • 73,842
  • 19
  • 118
  • 155