我正在尝试使用PHP将SQL值返回到HTML表中。除了最后一列"GROUP _ CONCAT (provision_id)."
相关代码:
<?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>
只是回显$content->provision-id
也不起作用。
答案 0 :(得分:12)
答案 1 :(得分:4)
如果你要获取对象,你应该在PHP中给你的列名称是合法的类成员标识符(我将链接到手册,尽管他们的description of valid variable names很可怕):
SELECT ... GROUP_CONCAT(provision_id) AS provisions