Php 如何从codeigniter中的视图获取数据
我不擅长codeigniter我还在学习这个。所以我需要你们的帮助 我想从数据库中获取id等于下拉列表按钮值的数据。这是我的代码 这是我的控制器:controller.php 我真的不知道在控制器里放什么 这是我的视图:view.php 这是从controller data.php调用的另一个视图Php 如何从codeigniter中的视图获取数据,php,html,database,codeigniter,Php,Html,Database,Codeigniter,我不擅长codeigniter我还在学习这个。所以我需要你们的帮助 我想从数据库中获取id等于下拉列表按钮值的数据。这是我的代码 这是我的控制器:controller.php 我真的不知道在控制器里放什么 这是我的视图:view.php 这是从controller data.php调用的另一个视图 请帮我解决这个问题。如果您不使用模型和数据库逻辑,请从控制器调用数据库库写入控制器查看以下内容: public function result() { $this->load->l
请帮我解决这个问题。如果您不使用模型和数据库逻辑,请从控制器调用数据库库写入控制器查看以下内容:
public function result()
{
$this->load->library('database')
$data = array();
$service_list = $this->db->query("SELECT * FROM loading_service WHERE member='".$q."'")->result_array();
$data['service'] = $service_list;
$this->load->view('result', $data);
}
在这个结果视图中,您可以得到$service数组,并且可以轻松地对其进行迭代 首先使用适当的模式和控制器切勿尝试在视图中执行DB查询查看@阅读文档,并尝试了解如何将数据从模型传递到控制器,从控制器传递到视图您必须完成codeigniter手册中的教程。学习框架的基础知识,然后开始构建。
Our model in CodeIgniter will be placed in application/models/form_model.php
<?php
class Form_model extends Model {
function Formmodel() {
// load the parent constructor
parent::Model();
}
function submit_posted_data() {
// db is initialized in the controller, to interact with the database.
$this->db->insert('loading_service ',$_POST);
}
function get_all_data() {
// again, we use the db to get the data from table ‘form’
$data['result']=$this->db->get('loading_service');
return $data['result'];
}
}
?>
controller
ss Form extends Controller {
function Form(){
// load Controller constructor
parent::Controller();
// load the model we will be using
$this->load->model('form_model');
// load the database and connect to MySQL
$this->load->database();
// load the needed helpers
$this->load->helper(array('loading_service','url'));
}
//Display the posted entries
function index() {
$data['member']='Form Data';
//use the model to get all entries
$data['result'] = $this->form_model->get_all_data();
// load 'forms_view' view
$this->load->view('forms_view',$data);
}
//Process the posted loading_service
function submit() {
//use the model to submit the posted data
$this->form_model->submit_posted_data();
redirect('loading_service');
}
}
?>
you can refer this code..It will helpful for u...
<?php
$q = intval($_GET['member']);
$con = mysqli_connect('localhost','root','','global89_point');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"global89_point");
$sql="SELECT * FROM loading_service WHERE member='".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>";
echo "<tr>";
echo " <th>";
echo "Member ID";
echo "</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['member'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
public function result()
{
$this->load->library('database')
$data = array();
$service_list = $this->db->query("SELECT * FROM loading_service WHERE member='".$q."'")->result_array();
$data['service'] = $service_list;
$this->load->view('result', $data);
}
Our model in CodeIgniter will be placed in application/models/form_model.php
<?php
class Form_model extends Model {
function Formmodel() {
// load the parent constructor
parent::Model();
}
function submit_posted_data() {
// db is initialized in the controller, to interact with the database.
$this->db->insert('loading_service ',$_POST);
}
function get_all_data() {
// again, we use the db to get the data from table ‘form’
$data['result']=$this->db->get('loading_service');
return $data['result'];
}
}
?>
controller
ss Form extends Controller {
function Form(){
// load Controller constructor
parent::Controller();
// load the model we will be using
$this->load->model('form_model');
// load the database and connect to MySQL
$this->load->database();
// load the needed helpers
$this->load->helper(array('loading_service','url'));
}
//Display the posted entries
function index() {
$data['member']='Form Data';
//use the model to get all entries
$data['result'] = $this->form_model->get_all_data();
// load 'forms_view' view
$this->load->view('forms_view',$data);
}
//Process the posted loading_service
function submit() {
//use the model to submit the posted data
$this->form_model->submit_posted_data();
redirect('loading_service');
}
}
?>
you can refer this code..It will helpful for u...