0

以下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;
  }
4

2 回答 2

1
while($users = $query->result_array()) {
    /* You can use $users['master_id'] here */
}
于 2012-08-12T23:14:29.200 回答
0
  1. 只有 1 个用户 week_email_f1 = 1
  2. $query->result_array(); 仅返回第一/最后/一行。
于 2012-08-12T17:51:54.960 回答