[英]PHP looping through array values in a query
我试图遍历一个数组并将行(值)用作我的SQL查询的条件,但我似乎无法使其遍历行。 它仅输出form_name = ' V243823'
然后停止的第一行的数据。 我需要所有行,所以总共要返回3个数组。
校园表格数组
[0] => Array
(
[PQ_Lookup] => V243823
[RL_Lookup] => B3823RL
[MA_Lookup] => F356823
)
foreach( $campus_forms[0] as $key => $row )
{
$this->db->select('form_deadline,form_url,form_fullname');
$this->db->from('form_deadlines');
$this->db->where('form_name', $row);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
$campus_forms = $query->result_array();
return $campus_forms;
}
}
在第一个循环中,由于这个原因,它不会执行下一个循环。请在foreach循环之后返回您的数据。您可以在每个循环中将数据保存在数组中,您可以这样进行:
$form_data_array = array();
foreach( $campus_forms[0] as $key => $row )
{
$this->db->select('form_deadline,form_url,form_fullname');
$this->db->from('form_deadlines');
$this->db->where('form_name', $row);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
$campus_forms = $query->result_array();
// return $campus_forms;
$form_data_array[] = $campus_forms;
}
}
return $form_data_array;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.