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.

2 Answers 2

12

Use an alias for the column.

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.