以下php函数仅适用于一条用户记录,而不是weekly_email_f1列中值为“1”的所有用户记录,有什么想法吗?
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;
}
有多个用户 week_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;
}