gpt4 book ai didi

php - 使用 codeigniter 在表单上显示每个数据

转载 作者:行者123 更新时间:2023-11-29 00:23:56 25 4
gpt4 key购买 nike

我是 CodeIgniter 的新手,正在探索它。我很难做到这一点。到目前为止,这是我尝试过的。

Controller.php

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Customer_controller extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('customer_model');
}
public function index()
{
$data['title']= 'Customer';
$data['records'] = $this->customer_model->getAll();
$data['groups'] = $this->customer_model->getAllCustomerGroups();
$data['groupcodes'] = $this->customer_model->getAllCustomerGroups();
$this->load->view('include/header',$data);
$this->load->view('include/navbar',$data);
$this->load->view('customer_view', $data);
$this->load->view('include/sidebar',$data);
$this->load->view('include/footer',$data);

}
}

模型.php

 function getAll() {
$query = $this->db->get('customercard');
return $query->row_array();
}

View.php

              <form class="form-horizontal" role="form">
<div class="form-group">
<label for="inputCustomerCode3" class="col-sm-2 control-label">Code</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputCustomerCode3" readonly>
</div>

<label for="inputWebsite3" class="col-sm-2 control-label">Website</label>
<div class="col-sm-4">
<input type="url" class="form-control" id="inputWebsite3" placeholder="Website">
</div>
</div>
<div class="form-group">
<label for="inputCustomerName3" class="col-sm-2 control-label">Name</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputCustomerName3" placeholder="Customer Name">
</div>

<label for="inputContact3" class="col-sm-2 control-label">Contact</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputContact3" placeholder="Contact">
</div>
</div>
<div class="form-group">
<label for="inputCustomerGroup3" class="col-sm-2 control-label">Group</label>


<label for="inputIncomeAccount3" class="col-sm-2 control-label">Income Account</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputIncomeAccount3" placeholder="Income Account">
</div>
</div>
<div class="form-group">
<label for="inputCustomerType3" class="col-sm-2 control-label">Type</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputCustomerType3" placeholder="Customer Type">
</div>
<label for="inputSalesPerson3" class="col-sm-2 control-label">Sales Person</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputSalesPerson3" placeholder="Sales Person">
</div>
</div>
<div class="form-group">
<label for="inputCustomerAddress3" class="col-sm-2 control-label">Address</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputCustomerAddress3" placeholder="Customer Address">
</div>

<label for="inputCreditLimit3" class="col-sm-2 control-label">Credit Limit</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputCreditLimit3" placeholder="Credit Limit">
</div>
</div>
<div class="form-group">
<label for="inputCustomerAddressAlt3" class="col-sm-2 control-label">AddressAlt</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputCustomerAddressAlt3" placeholder="Customer AddressAlt">
</div>

<label for="inputTin3" class="col-sm-2 control-label">Tin</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputTin3" placeholder="Tin">
</div>
</div>
<div class="form-group">
<label for="inputPhone13" class="col-sm-2 control-label">Phone1</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputPhone13" placeholder="Phone1">
</div>

<label for="inputTaxCode3" class="col-sm-2 control-label">Tax Code</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputTaxCode3" placeholder="Tax Code">
</div>
</div>
<div class="form-group">
<label for="inputPhone23" class="col-sm-2 control-label">Phone2</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputPhone23" placeholder="Phone2">
</div>

<label for="inputTerms3" class="col-sm-2 control-label">Terms</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputTerms3" placeholder="Terms">
</div>
</div>
<div class="form-group">
<label for="inputFax3" class="col-sm-2 control-label">Fax</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputFax3" placeholder="Fax">
</div>

<label for="inputPriceCode3" class="col-sm-2 control-label">Price Code</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputPriceCode3" placeholder="Price Code">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-4">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-6 col-sm-10">
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-backward"></span>
</button>
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-arrow-left"></span>
</button>
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-arrow-right"></span>
</button>
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-forward"></span>
</button>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-4 col-sm-10">
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Add</button>
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span> Update</button>
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Save</button>
<button type="button" class="btn btn-primary"><span class="glyphicon glyphicon-remove"></span> Delete</button>
<button type="reset" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Cancel</button>
</div>
</div>
</form>

我想做的是将数据库中的数据显示到我的表单中。我选择了

  $query = $this->db->get('customercard');

产生

  SELECT * FROM customercard

但我想在表单上显示每条记录,然后如您所见,我有导航按钮,第一个、上一个、下一个和最后一个。我想使用这些按钮循环播放记录。我不知道如何在 View 中显示它。所以我要求你给我一些入门教程或帮助我编写代码,以便我可以继续我正在做的事情。非常感谢您的帮助。提前谢谢大家!

最佳答案

将模型更改为

function getAll() {
$query = $this->db->get('customercard');
return $query->result_array();
}

另请注意,当您将 $data['records'] 传递给 View 时,您只需从 View 中通过 $records 即可访问它。

在您看来,只需循环遍历即可。

<?php
foreach ($recordsas $value)
{
echo "$value <br>";
}
?>

------------您可以尝试以下操作。这是一种根据您的需要获取下一条记录的简单方法。

型号

public function fetch_customers($limit, $start) {
$this->db->select('customercode,customername,customergroup,customertype,customeraddress,website');
$this->db->limit($limit);
$this->db->where('customercode >',$start);
$this->db->order_by('customercode');
$query = $this->db->get('customercard');
if ($query->num_rows() > 0) {
$row = $query->row();
$data[] = $row;
return $data;
} else {
return false;
}
}

Controller

public function index(){
$shown_id = 0;
if(isset($this->uri->segment(3)){
$shown_id = $this->uri->segment(3);
}
$this->load->model('customers_model');
$data['info'] = $this->customers_model->fetch_customers(1,$shown_id);
$this->load->view('customer_info',$data);
}

查看

$customer_id = $info->customercode;
$customer_name = $info->customername;
//Use like above to get the customer info and show as you like

但是,当您制作“下一步”按钮时,您需要将 $customer_id 传递回 Controller 。您也可以让超链接执行此操作。

<a href="<?php echo base_url();?>controller_name/index/<?php echo $customer_id;?>"

或者使用带有 onclickwindow.location 的按钮

关于php - 使用 codeigniter 在表单上显示每个数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19945931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com