空结果为特定列 - php / mysql

时间:2012-03-13 16:14:52

标签: php mysql

我的查询在数据库上执行时返回正确的数据,但在运行时,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>
<?
}
?>

1 个答案:

答案 0 :(得分:1)

尝试在您的某些字段中添加COALESCE

像这样:

SELECT ..., COALESCE(company_title, ''),
            COALESCE(company_name, '')
        ...

而不是null值,它将返回空字符串