Reputation: 415
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.
Upvotes: 5
Views: 2471
Reputation: 75704
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
Upvotes: 4
Reputation: 96159
Use an alias for the column.
GROUP_CONCAT( provision_id ) as pids
...
echo $content->pids
Upvotes: 12