我想从我的数据库表中获取大学ID。输入来自所选选项。
HTML
<li>
<h4>University with cost range</h4>
</li>
<select name="costing">
<option value="1" selected="less than 2 lacs">less than 2 lacs</option>
<option value="2">2 lacs - 4 lacs</option>
<option value="3">4.1 lacs - 6 lacs</option>
<option value="4">6.1 lacs - 8 lacs</option>
<option value="5">8.1 lacs - 10 lacs</option>
<option value="6">More than 10 lacs</option>
</select>
<input type="submit" value="Proceed" />
</form>
模型
public function university_cost()
{
$data = $this->input->post('costing');
if($data == "1")
{
$this->db->select('U_ID')->from('cost')->where("Total_cost BETWEEN 00 AND 400000");
$subQuery = $this->db->get_compiled_select();
$this->db->select('U_ID, U_Name, Min_result_to_apply')
->from('university')
->where("U_ID IN ($subQuery)", NULL, FALSE);
return $this->db->get()->result_array();
}
if($data == "2")
{
$this->db->select('U_ID')->from('cost')->where("Total_cost BETWEEN 600000 AND 800000");
$subQuery = $this->db->get_compiled_select();
$this->db->select('U_ID, U_Name, Min_result_to_apply')
->from('university')
->where("U_ID IN ($subQuery)", NULL, FALSE);
return $this->db->get()->result_array();
}
}
错误
<?php foreach($cost as $row1){?>
<tr >
<td><?php echo `enter code here`$row1['U_ID']?></td>
<td><?php echo $row1['U_Name']?></td>
<td><?php echo $row1['Min_result_to_apply']?></td>
<?php }?>
请帮忙。我尝试了几种方法,但是当我得到答案时,我得到了所有......就像所有的大学ID一样
控制器代码
public function university_by_cost()
{
$this->load->model('university_model');
$data5['cost'] = $this->university_model->university_cost();
$this->load->view('cost_uni',$data5);
}
错误页面
严重性:警告
消息:为foreach()提供的参数无效
文件名:views / cost_uni.php