Reputation: 199
Hello in my codeigniter project one textbox field values is not inserting into db.
How to pass value from view to controller and vice-versa?
View Code( Here we enter the Ex-showromm Price,suppose 1500)
when we hit Bill button The value have to enter into db and and print it as a bill.
$actual_price=0;
if(count($list_product) >0) {
foreach($list_product as $key=>$item) {
$total +=$item['salePrice'];
?>
<tr>
<td bgcolor="#CCCCCC"> <?=$item['model']." ".$item['variant']?>
<br /> <?=$item['vin']?> </td>
<td bgcolor="#CCCCCC">
<?=$item['saleQty']?></td>
<td colspan="2" bgcolor="#CCCCCC"><input type="text" name="price" id="price" size="13px"/></td>
<td colspan="2" bgcolor="#CCCCCC"><input type="text" name="actual_price" id="actual_price" size="13px"/></td>
</tr>
<?php }}?>
<tr>
<td colspan="4" align="center" valign="middle" bgcolor="#E0DFE3" class="cont"> <input name="tot_price" type="hidden" id="tot_price" size="50" value="<?=$total?>" /></td>
<td colspan="4" align="center" valign="middle" bgcolor="#E0DFE3" class="cont"> <input name="actual_price" type="hidden" id="actual_price" size="50" value="<?=$actual_price?>" /></td>
Bill View
The value from the database has been passed to a variable in the report
Upvotes: 0
Views: 222
Reputation: 199
Problem have been solved. My changes to code are as follows
Sales Page
<td colspan="2" bgcolor="#CCCCCC"><input type="text" name="exshowroom" id="exshowroom" size="13px"/></td>
</tr>
Controller
function bill()
{
$actual_price=$this->input->post('exshowroom');
$data['list_product'][0]['actual_price']=$actual_price;
}
$arrInsert =array (
"actual_price" =>$actual_price
);
$saleId=0;
if($this->product_model->insert_sale_entry($arrInsert)){
$saleId = $this->db->insert_id() ;
$arrStatus =array (
"productSaleStatus" =>1
);
Passing Input value to Next View page ie,Report
$data['exshowroom'] =$this->input->post('exshowroom');
$this->load->view('header_login');
$this->load->view('catalog/bill',$data);
Reprort View Page
<td height="33" align="center" valign="middle" class="cont"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Total Ex-ShowRoom Price of the Vehicle: </strong></font>: <font size="2"> </font>
<td align="center"><font size="2" face="Arial, Helvetica, sans-serif">
<?=$exshowroom?></font> </td>
</tr>
Now am happy:) Thanks to all
Upvotes: 0
Reputation: 5695
To pass a value to the view, you add it to an array and pass it to the view like so:
$Data['Pies'] = array('Cherry', 'Key Lime');
$Data['Cakes'] = array('Funfetti');
$Data['Paperplates'] = true;
$this->load->view('picnic', $Data);
CodeIgniter automatically unpacks the data on the view side, so you access it like so:
The first pie is <?=$Pies[0] ?>
<?php if ($Paperplates) { ?>
Don't bring plates <?php
} else { ?>
Bring plates please
<?php }
will print:
The first pie is Cherry
Don't bring plates
Regarding returning values to the controller: you don't, at least not the way you're thinking. In order to get variables back you'll need them to be sent from the browser using a POST
or GET
request.
I suggest you start off by reading the CodeIgniter User Guide.
Upvotes: 2