下面的php函數只能用於一個用戶記錄,並不是所有的用戶記錄在weekly_email_f1列中的值爲「1」,任何想法?php函數沒有循環遍歷所有用戶,只是第一個用戶
function getSummaryEmailInfo() {
$sql = "
SELECT u.id, u.master_id, u.email
FROM user AS u
WHERE u.weekly_email_fl = 1
";
$query = $this->db->query($sql);
$users = $query->result_array();
foreach ($users as &$user) {
$user_id = ($user['master_id'] == '0') ? $user['id'] : $user['master_id'];
$sql = "
SELECT ui.custom_name
FROM user_item AS ui
WHERE ui.user_id = '" . $user_id . "'
AND added_to_list_dt IS NOT NULL
ORDER BY added_to_list_dt DESC
;
";
$query = $this->db->query($sql);
$user['s_list'] = $query->result_array();
}
return $users;
}
有多個用戶與weekly_email_f1 = 1,我覺得有什麼不對與result_array()如何;被填充,但無法弄清楚,可是...
function getUserInfo($user_id) {
$query = $this->db->query("
SELECT name AS first_name, email, zip_code, weekly_email_fl
FROM user
WHERE id = '" . $user_id . "'
;");
if ($query->num_rows() > 0) {
$results = $query->result_array();
$results = $results[0];
} else {
$results = null;
}
return $results;
}
有你測試的功能,無需在foreach循環來檢查問題是否是內部或外部的循環? – 2012-08-12 17:53:14