特定列的空结果-php/mysql

特定列的空结果-php/mysql,php,mysql,Php,Mysql,我的查询在db上执行时返回正确的数据,但在运行live时,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->que

我的查询在db上执行时返回正确的数据,但在运行live时,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>
<?
}
?>
$query=“从发票i、公司查找cl、学生s中选择*,其中i.company\u id=cl.company\u id和i.student\u id=s.student\u id;”;
$results=$DB->query($query);
$invoices=mysql_查询(“从发票中选择*);
?>
月/年
全额
单位

尝试在某些字段中添加
COALESCE

像这个:

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

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

您确定live和您的开发机器上的数据库是相同的吗?在您使用的任何表中是否确实有公司名称字段?仅仅因为你可以在PHP数组引用中使用你想要的任何键(你的$行),并不意味着MySQL实际上有一个对应的字段结果。@ini因为你得到的是
$invoices
而不是
$query
try
$results['company\u name']
很难从你的代码中分辨出来,因为“*”,但公司名称在$results资源中,而不是$invoices资源中。ie公司名称不在$row数组中,因为您正在迭代错误的结果$invoices not$results.closer!使用$results返回一个公司名称,但它不能区分不同的名称。company_id为1或2,具有不同的company_名称,包含company 2的记录显示为company 1。有什么想法吗?在myPHPadmin中运行查询时,公司名称正确显示