codeigniter 如何在PHP中使用一个foreach执行两个不同的查询

mfuanj7w  于 2022-12-20  发布在  PHP
关注(0)|答案(1)|浏览(145)

我正在使用Php,现在我正在使用foreach循环(传递数组)插入查询,但是我如何使用另一个查询foreach并将值传递到同一个数组中呢?

$data=$this->db->get($firstquery) // first query record in array
$second=$this->db->get($second_query);  // second query record in array
foreach($records as $rec)
{
   $data22 = array
        (
                'file_id'=>$rec['id'],  // here is first query result
                'text'=>    // How to pass second query result here 
        );
}
n3ipq98p

n3ipq98p1#

可以在主循环内调用另一个循环并执行另一个查询

$data=$this->db->get($firstquery) // first query record in array
$second=$this->db->get($second_query);  // second query record in array
foreach($records as $rec)
{   
         foreach($second as $sec)   //second query loop
         {
          //enter code here
         }
   $data22 = array
        (
                'file_id'=>$rec['id'],  // here is first query result
                'text'=>    // How to pass second query result here 
        );
}

相关问题