我的查询在数据库上执行时返回正确的数据,但是当实时运行时,company_title 返回 null。所有其他字段都有效。 $row['company_name'] 是我无法工作的代码:
$query = "select * from invoices i, company_lookup cl, students s where i.company_id = cl.company_id and i.student_id = s.student_id;";
$results = $DB->query($query);
$invoices = mysql_query("select * from invoices");
?>
<table border="1" id="hl" name="hl">
<tr>
<th>Month/Year</th>
<th>Full Amount</th>
<th>Company</th>
</tr>
<?php while ($row = mysql_fetch_array($invoices)) {
$invoice_date = $row['invoice_date'];
?>
<tr onMouseOver="showInvoicePayments(<? echo $row['invoice_id'] ?>);this.bgColor = '#C0C0C0'" onMouseOut ="this.bgColor = '#FFFFFF'" bgcolor="#FFFFFF">
<td><? echo date('F Y',strtotime($invoice_date)) ?></td>
<td><? echo '$' . $row['full_amount'] ?></td>
<td><? echo $row['company_name'] ?></td>
</tr>
<?
}
?>
最佳答案
尝试在某些字段中添加COALESCE
。
喜欢这个:
SELECT ..., COALESCE(company_title, ''),
COALESCE(company_name, '')
...
它将返回一个空字符串,而不是null
值。
关于php - 特定列的空结果 - php/mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9687827/