【发布时间】:2020-02-04 08:29:13
【问题描述】:
这是我的资源首先
正如您在我的数据库中看到的,我有一个 Referal_Code 和 Referral_Link
现在我在这里尝试的是,我想获得所有在Referal_Code 上具有相同值的Referral_Link
我知道我离我想要做的事情还很远,但我正在尽我最大的努力来完成这件事。 这是我到目前为止所尝试的
在我的model
public function get_same_referral_code()
{
$this->db->select('referal_code');
$this->db->where('referal_code', 'PoVsw0Epne');
$query = $this->db->get('investor');
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
}
还有我的controller
public function get_all()
{
$data = array();
$data['title'] = "Rewards";
$data["data"] = $this->investor->get_all_investor();
$data["get_all_flevel"] = $this->investor->get_all_first_level();
$data["referrals"] = $this->investor->get_same_referral_code();
$this->template->load('default_layout','contents','rewards',$data);
}
我在我的view 上这样称呼它
<?php
echo ($referrals[0][id]);
echo ($referrals[0][firstname]);
echo ($referrals[0][referal_code]);
echo ($referrals[0][referral_link]);
?>
我的预期结果应该是这样的
谁能帮帮我。
编辑
我再次尝试过这种方式以获得我想要的东西。
首先我尝试获取所有referal_code
public function get_same_referral_code()
{
$this->db->select('referal_code');
$query = $this->db->get('investor');
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
}
现在我将使用这个方法get_same_referral_code() 来检查是否
referral_link 在referal_code 上具有相同的值
public function get_same_referral_link()
{
$this->db->select('referral_link');
$this->db->where('referral_link','get_same_referral_code();');
$query = $this->db->get('investor');
if($query->num_rows() > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
但问题是我现在遇到了这个错误
消息:为 foreach() 提供的参数无效
【问题讨论】:
标签: php jquery mysql codeigniter