dousheyan0375 2013-12-14 18:50
浏览 39
已采纳

Codeigniter插入代码不起作用

Hello in my codeigniter project one textbox field values is not inserting into db. Sale View

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">&nbsp;<?=$item['model']."&nbsp;&nbsp;".$item['variant']?>
         <br />&nbsp;<?=$item['vin']?> &nbsp;&nbsp;</td>
        <td bgcolor="#CCCCCC">&nbsp;
          <?=$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">&nbsp;<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">&nbsp;<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 Report View

  • 写回答

2条回答 默认 最新

  • dongluan1901 2013-12-14 18:59
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?