我想要在用戶儀表板上自動顯示這些結果,當用戶登錄到他們的儀表板時,我希望此查詢運行並向他們顯示其用戶ID的統計信息。請建議如何做到這一點。如何獲得登錄用戶ID,統計的工作代碼在下面發佈。獲取登錄從codeigniter會話中的用戶ID
echo '<pre>'; print_r($this->session->all_userdata());exit;
我越來越:
<?php
$query = $this->db->query("SELECT
tblclients.userid as client_id,
tblclients.company as company_name,
IFNULL(tblinvoices.total, 0) AS total_amount,
IFNULL(tblinvoicepaymentrecords.amount, 0) AS paid_amount,
(IFNULL(tblinvoices.total, 0) - IFNULL(tblinvoicepaymentrecords.amount, 0)) AS amount_due
FROM
tblclients
LEFT JOIN tblinvoices ON tblclients.userid = tblinvoices.clientid
LEFT JOIN tblinvoicepaymentrecords ON tblinvoices.id = tblinvoicepaymentrecords.invoiceid
WHERE tblclients.userid = 1");
foreach ($query->result_array() as $row)
{
echo $row['total_amount'] . " " . $row['paid_amount'] . " " .$row['amount_due'];
echo "<br />";
}
?>
檢查這個代碼後
Array
(
[__ci_last_regenerate] => 1504507372
[client_user_id] => 1
[contact_user_id] => 1
[client_logged_in] => 1
[red_url] => https://www.trisuka.com/crm/admin
)
任何人,請幫幫忙。 –
如何獲得用戶登錄? ?您必須將它存儲在codeigniter會話中? ? –
@Root Ingenious:謝謝你在這裏,好友,是的,我已經存儲了,但正如你可以看到上面的代碼,一個是由你給出的完整的sqlquery,我將如何在選擇語句中應用用戶ID,現在它是手動userid = 1 ..或者我必須從數據庫中獲取所有的用戶ID和結果,將不得不篩選使用會話。 –