2012-03-13 3 views
0

내 쿼리는 db에서 실행될 때 올바른 데이터를 반환하지만 live를 실행하면 company_title이 null로 돌아옵니다. 다른 모든 필드는 작동합니다. 당신의 일부 필드에 COALESCE을 추가특정 열에 대한 결과가 없습니다. PHP/mysql

$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

실생활과 개발자 머신의 데이터베이스가 동일합니까? – kirilloid

+0

사용중인 테이블에 실제로 company_name 필드가 있습니까? PHP 배열 참조 ($ 행)에서 원하는 키를 사용할 수 있다고해서 실제로 MySQL의 해당 필드 결과가 있음을 의미하지는 않습니다. –

+0

'$ invoices' 행에'$ query'가 아닌 행이 있기 때문에 @ini 결과가 나오기 때문에 @ini 결과가 나타납니다. $ results [ 'company_name'] ' – mgraph

답변

1

시도 : $ 행 [ 'COMPANY_NAME은'] 내가 일을 얻을 수없는 코드입니다. 이와 같은

:

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

대신 null 가치, 그것이 빈 문자열을 반환합니다.

관련 문제