0

我正在尝试在每个循环上使用新的“WHERE (AND)”子句查询数据库。new 子句只是循环的编号。

我需要将每个循环返回的行数保存在我正在努力解决的数组中。

例如,如果有两个循环,第一个循环返回 2 行,第二个 3。我希望数组本质上是:

$portfolio_list = array(2,3); 

据我所知,这就是它无法正常工作的结果,不足为奇。

任何帮助都会很棒!

$portfolios = 2;

$i = 1;

$portfolios_list = array();

while ($i <= $portfolios) {

    $portfolio_sql = "
        SELECT COUNT(portfolio_number) AS portfolio_uploaded_images
        FROM exp_submissions
        WHERE member_id = $member_id
        AND type_id = '1' 
        AND portfolio_number = $i
    ";

    $query = $this->EE->db->query($portfolio_sql);

    $return = $query->result();
    $portfolios_list[] = $return;

    $i++;
}
4

2 回答 2

1

请试试这个

$portfolios = 2;

for ($i = 1; $i < $portfolios+1; $i++) { //this runs 2 times

    $where_array = array('member_id' => $member_id, 'type_id' => '1', 'portfolio_number' => $i);
    $this->db->where( $where_array );
    //$this->db->select('*'); // I guess you do not need select for this
    $portfolio_list[$i] = $this->db->get('exp_submissions')->num_rows(); 

}

var_dump($portfolio_list);
于 2013-09-19T14:17:19.560 回答
0

尝试这个

$portfolios = 2;

$i = 1;


while ($i <= $portfolios) {

    $portfolio_sql = "
        SELECT COUNT(portfolio_number) AS portfolio_uploaded_images
        FROM exp_submissions
        WHERE member_id = $member_id
        AND type_id = '1' 
        AND portfolio_number = $i
    ";

    $query = $this->db->query($portfolio_sql);
    $portfolios_list[$i] = $query->num_rows; // This will give the No of rows fetched 
    $i++;                                                                                         
}
foreach($portfolios_list as $row => $no)
{
   echo "The Results Fetched from query no ".$row." is ".$no;
} 
于 2013-09-19T09:49:47.200 回答