我想显示多个下拉列表选择的搜索结果。我有4个下拉菜单。我有一个提交按钮,但是当我点击提交按钮时,我仍然很困惑如何显示搜索结果。我想根据下面 mymodel.php 中的查询,在“课程”表中显示“机构”和“地址”列,并在不匹配时显示“无结果” 。我想在http://www.bhinneka.com/category/notebook___laptop_gaming.aspx上显示搜索结果(机构图片,机构名称和地址)。
我是否需要新页面来显示搜索结果?
我尝试了很多方法,但仍然失败了:(
非常感谢您的回答!
以下是我的代码(使用Codeigniter):
Controller.php这样
class Controller extends CI_Controller
{
public function index()
{
$this->load->view('home');
}
}
mymodel.php
class Mymodel extends CI_Model
{
public function getinstitution()
{
include('application/views/home.php');
$institution = $_POST['DropdownInstitution'];
$course = $_POST['DropdownCourse'];
$location = $_POST['DropdownLocation'];
$price = $_POST['DropdownPrice'];
$this->db->select('*');
$this->db->from('courseplace');
$this->db->where('1 = 1');
if ($institution != '') {
$this->db->where('institution', $institution);
}
if ($course != '') {
$this->db->where('course', $course);
}
if ($location != '') {
$this->db->where('location', $location);
}
if ($price != '') {
$this->db->where('price', $price);
}
$data = $this->db->get()->result_array();
return $data;
}
}
home.php
<div class="MenuSearching" id="Searching">
<form action="" method="post">
<div class="Menu1" id="Menu1">
<p> Lembaga</p>
<div style="margin-top:-20px;margin-left:-2px;">
<select name="DropdownInstitution" autofocus required id="DropdownInstitution">
<option value="no" selected="selected">---Choose one---</option>
<option value="FlashCom">FlashCom</option>
<option value="InterNusa">InterNusa</option>
<option value="HexaCompare">HexaCompare</option>
</select>
</div>
</div>
<div class="Menu2" id="Menu2">
<p> Paket Kursus</p>
<div style="margin-top:-20px;margin-left:-2px;">
<select name="DropdownCourse" autofocus required id="DropdownCourse">
<option value="no" selected="selected">---Choose one---</option>
<option value="web">Kursus Web Design</option>
<option value="flash">Kursus Flash Animation</option>
<option value="marketing">Kursus Internet Marketing</option>
</select>
</div>
</div>
<div class="Menu3" id="Menu3">
<p> Lokasi</p>
<div style="margin-top:-20px;margin-left:-3px;">
<select name="DropdownLocation" autofocus required id="DropdownLocation">
<option value="no" selected="selected">---Choose one---</option>
<option value="timur">Surabaya Timur</option>
<option value="barat">Surabaya Barat</option>
<option value="utara">Surabaya Utara</option>
<option value="selatan">Surabaya Selatan</option>
</select>
</div>
</div>
<div class="Menu4" id="Menu4">
<p> Harga</p>
<div style="margin-top:-20px;margin-left:-2px;">
<select name="DropdownPrice" autofocus required id="DropdownPrice">
<option value="no" selected="selected">---Choose one---</option>
<option value="harga1"> kurang dari Rp.750.000</option>
<option value="harga2">Rp.750.000 - Rp.1.500.000</option>
<option value="harga3">Rp.1.500.000 - Rp.2.500.000</option>
<option value="harga4">lebih dari Rp.2.500.000</option>
</select>
</div>
</div>
<div>
<input name="submitbutton" type="submit" id="submitbutton" formmethod="POST" value="Submit">
</div>
</form>
答案 0 :(得分:0)
您可以使用jQuery + Ajax来解决此非刷新问题。 在home.php文件中,向您的控制器发送请求,并在模型返回数据到控制器后,数据将附加到您的网页上。
答案 1 :(得分:0)
我建议你通过模型,视图和控制器的codeigniter演示。 请检查以下代码
<强> Controller.php这样强>
//make a call to getinstitution function
//load our Mymodel class defined in mymodel.php
//call your view home
class Controller extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->model('Mymodel');
}
public function index()
{
$params = array(
'DropdownInstitution' => $this->input->post('DropdownInstitution'),
'DropdownCourse' => $this->input->post('DropdownCourse'),
'DropdownLocation' => $this->input->post('DropdownLocation'),
'DropdownPrice' => $this->input->post('DropdownPrice'),
);
$data['result'] = $this->mymodel->getinstitution($params);
$this->load->view('home',$data);
}
}
<强> mymodel.php 强> //无需包含(&#39; application / views / home.php&#39;); //
class Mymodel extends CI_Model
{
public function getinstitution($params)
{
$institution = $params['DropdownInstitution'];
$course = $params['DropdownCourse'];
$location = $params['DropdownLocation'];
$price = $params['DropdownPrice'];
$this->db->select('*');
$this->db->from('courseplace');
$this->db->where('1 = 1');
if ($institution != '') {
$this->db->where('institution', $institution);
}
if ($course != '') {
$this->db->where('course', $course);
}
if ($location != '') {
$this->db->where('location', $location);
}
if ($price != '') {
$this->db->where('price', $price);
}
$data = $this->db->get()->result_array();
return $data;
}
}
<强> home.php 强>
请添加以下代码以查看home.php
<div>
<?php if(!empty($result)){
foreach($result as $value){ ?>
<?php echo $value ?>
<?php }
}else{
echo 'No results';
} ?>
</div><!--Result div-->