问题描述
我想知道在Codeigniter中最相关的方法。我实际上是用它来填充< options> < / options>
的格式为
I want to know the most relevant method to do this in Codeigniter. I was actually using this to populate <options> </options>
in form
<div class="form-group">
<label for="int">Clients Id <?php echo form_error('clients_id') ?></label>
<select class="form-control select2 select2-hidden-accessible" se="width: 100%;">
<center><option selected="selected">--- Select ---</option></center>
<?php
foreach ($invoices as $invoices) {
?>
<option class="form-control select2" value=" <?php echo $invoices->clients_id; ?>"><?php echo $invoices->first_name; ?>
</option>
<?php
}
?></select>
</div>
<div class="form-group">
<label for="int">Suppliers Id <?php echo form_error('suppliers_id') ?></label>
<select class="form-control select2 select2-hidden-accessible" se="width: 100%;">
<center><option selected="selected">--- Select ---</option></center>
<?php
foreach ($invoices as $invoices) {
echo "<pre>"; print_r($invoices);die;
?>
<option class="form-control select2" value=" <?php echo $invoices->service_id; ?>"><?php echo $invoices->service_name; ?>
</option>
<?php
}
?></select>
</div>
此功能在我的模型中。有没有最好的执行方法。
This function is in my model. Is there any best method to execute.
function join() {
$this->db->select('*');
$this->db->from('invoices');
$this->db->join('clients', 'invoices.id = clients.id');
$this->db->join('services', 'invoices.id = services.id');
$query = $this->db->get();
return $query->result();
}
这是正确的方法吗?调用发票数据。实际上,整个代码都能正常工作,但是当我调用 foreach()
时,显示错误。
Is it the right method. To call the Invoice data. Actually, entire code works properly but when I call foreach()
It, Shows error. Thank you in Advance.
public function create()
{
$data = array(
'button' => 'Create',
'action' => site_url('invoices/create_action'),
'id' => set_value('id'),
'clients_id' => set_value('clients_id'),
'services_id' => set_value('services_id'),
'suppliers_id' => set_value('suppliers_id'),
'contractors_id' => set_value('contractors_id'),
'charges_id' => set_value('charges_id'),
'particulars' => set_value('particulars'),
'details' => set_value('details'),
'price' => set_value('price'),
'date' => set_value('date'),
'due' => set_value('due'),
'paid' => set_value('paid'),
);
$this->load->view('invoices_form', $data);
}
推荐答案
首先检查您的查询使用 echo $ this-> db-> last_query();
将此代码放入 controller
中,您在其中编写 $ data ['invoices']
,然后检查其是否工作,然后在您的视图
部分中使用以下代码。
First of all check your query using echo $this->db->last_query();
put this code in controller
where you write $data['invoices']
and then check its working or not then use below code in your view
part.
<div class="form-group">
<label for="int">Clients Id <?php echo form_error('clients_id') ?></label>
<select class="form-control select2 select2-hidden-accessible" style="width: 100%;">
<center><option selected="selected">--- Select ---</option></center>
<?php
foreach ($invoices as $row)
{
echo '<option class="form-control select2" value="'.$row['client_id'].'">'.$row['first_name'].'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="int">Suppliers Id <?php echo form_error('suppliers_id') ?></label>
<select class="form-control select2 select2-hidden-accessible" se="width: 100%;">
<center><option selected="selected">--- Select ---</option></center>
<?php
foreach ($invoices as $row)
{
echo '<option class="form-control select2" value="'.$row['service_id'].'">'.$row['service_name'].'</option>'
}
?>
</select>
</div>
这篇关于如何在一种形式的Codeigniter中使用foreach来获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!