簡體   English   中英

OO Mysqli PHP數據未正確顯示

[英]OO Mysqli PHP data isn't displaying correctly

我正在嘗試使用while循環在表中顯示信息,但是如果只有1個結果,則該表將不顯示任何內容。 如果大於1,將顯示結果-1。 例如,對於5個結果,它將僅顯示5。

我的查詢是:

$queryIndexInvoice = 
"SELECT * 
FROM invoices, clients, users
WHERE invoices.user_id = users.id
AND invoices.client_id = clients.id
AND invoices.estimate = 0
AND invoices.user_id = '$user_id'
AND deleted = 0
ORDER BY invoices.id
DESC LIMIT 5";

$resultIndexInvoice = $connect_db->query($queryIndexInvoice);
$rowIndexInvoice = $resultIndexInvoice->fetch_assoc();
$numIndexInvoice = $resultIndexInvoice->num_rows;

我的表是:

<tbody>
<?php while ($IndexInvoice = $resultIndexInvoice->fetch_assoc()) {?>    
    <tr class='table_items'>
    <td class='item_strip'></td>
    <th><input type='checkbox'></th>
    <td><?= $IndexEstimate['invoice_id'] ?></td>
    <td><?= $dateIndexEstimate ?></td>
    <td><?= $IndexEstimate['client_first']?> <?= $IndexEstimate['client_last']?></td>
    <td><?= $IndexEstimate['total'] ?></td>
    </tr>
<?php
}
?>
</tbody>

有人知道我在做什么錯嗎?

您的問題是您正在調用->fetch_assoc(); 在結果集上,在循環之前,因此當您進入循環時,內部指針位於返回的第二行。 您需要刪除$rowIndexInvoice = $resultIndexInvoice->fetch_assoc();

$resultIndexInvoice = $connect_db->query($queryIndexInvoice);
$rowIndexInvoice = $resultIndexInvoice->fetch_assoc(); <--Remove this line
$numIndexInvoice = $resultIndexInvoice->num_rows;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM