使用PHP中的for循环使用数组值从数据库中获取数据



阵列:

$ecodesAr = Array ( 
[0] => 1Z0-060 
[1] => 98-375 
[2] => 98-368 
[3] => 98-367 )
for($k=0; $k<count($ecodesAr); $k++){ 
$arrayTB[$k] = $this->Functions->exam('title', $ecodesAr[$k]); }                         


模式代码:

public function exam($q, $d) {
$q = $this->db->where($q, $d)
->get('exams');
return $q->row();
}

结果:

Array ( 
[0] => 
[1] => 
[2] => 
[3] => stdClass Object ( [id] => 1091 [hot_exam] => 0 [top_exam] => 0 [category] => 114 [subcats] => 288 [slug] => 98-367 [sku] => OI5Ao [title] => 98-367 [name] => MTA Security Fundamentals [update] => 2021-09-16 [regular_price] => 130 [sale_price] => 59 [on_homepage] => 0 [on_request] => 0 [expired] => 0 [path_slug] => 98-367.pdf [questions] => 123 [demo_slug] => 98-367-demo.pdf [prc_price] => 65 [prc_demo] => 98-367-demo [prc_exam] => 98-367 [is_active] => 1 ) 
)

前3个值在输出中被跳过,只得到最后一个值,我希望所有数组数据都与值相对应,请帮助任何人!

$productsarry = Array ( 
[0] => Milk 
[1] => Cream 
[2] => Sugar 
[3] => Yougert
);
for($k = 0; $k < count($productsarry); $k++) { 
$arrayTB[$k] = query("select slug, qty, name, price from exams where title ='$ecode'")->row(); 
}

相关内容

  • 没有找到相关文章

最新更新