ci shopping cart

#1
[eluser]Unknown[/eluser]
how to store the items to the cart if the item are coming from database
here is the code of view file below which does not show me the items added to the cart.
<?
else if($page_req=='shoppinglist') { ?>
<form action="<?=base_url()?>checkout" method="post">

<table><tr><td>Product Name </td><td>Price</td><td>Quantity</td></tr>
<tr>
&lt;? foreach($this->cart->contents() as $items)
{










?&gt;



<td>&lt;? echo $items['pname']; ?&gt; </td>
<td>&lt;? } ?&gt; </td>
</tr></table>

&lt;input type="text" name="qty"&gt;

&lt;/form&gt;


&lt;? } ?&gt;
here is the controllers code below
else if($req=='shoppinglist')
{
$req=$this->uri->segment(4);
$sqlselect="select * from shopping where id='$req'";
$query=mysql_query($sqlselect) or die(mysql_error());
while($rec=mysql_fetch_array($query))
{

$id=$rec['id'];
$pname=$rec['name'];
$pprice=$rec['price'];
$qty=$this->input->post('qty');



}

$this->load->library('cart');
$productarray=array('id'=>$id,'pname'=>$pname,'pprice'=>$pprice,'qty'=>$qty);

print_r($productarray);
//$data['productarray']=$productarray;
$cartinsert=$this->cart->insert($productarray);



$data['title'] = 'Ziplance Lab Hosting Service| Penny auction script | Dating script | Freelance script | Zip Lance Lab | Ziplancer';
$data['meta_keywords'] = 'Excellent Penny auction script, Ziplane lab product list.';
$data['meta_description'] = 'Zip Lance Lab providing excellent product at cheapest rate.';
$data['page_req']='shoppinglist';
$this->load->view('full_page',$data);


}

#2
[eluser]Clooner[/eluser]
Added code tags to make it more readable
Code:
&lt;?
else if($page_req==‘shoppinglist’)  {  ?&gt;
                          &lt;form action=”&lt;?=base_url()?&gt;checkout” method=“post”&gt;
                        
                        <table><tr><td>Product Name </td><td>Price</td><td>Quantity</td></tr>
                        <tr>
                        &lt;?  foreach($this->cart->contents() as $items)
                          {
                              
                            
                            
                        
                        
                        
                        
                        
                        
                        
                        ?&gt;
                            
                        
                        
                        <td>&lt;? echo $items[‘pname’]; ?&gt; </td>
                        <td>&lt;? } ?&gt;  </td>
                        </tr></table>
                          
                          &lt;input type=“text” name=“qty”&gt;
                      
                        &lt;/form&gt;                            
                                                  
                                                  
                    &lt;?  }  ?&gt;
here is the controllers code below
else if($req==‘shoppinglist’)
                  {
                          $req=$this->uri->segment(4);
                          $sqlselect=“select * from shopping where id=’$req’”;
                          $query=mysql_query($sqlselect) or die(mysql_error());
                          while($rec=mysql_fetch_array($query))
                          {
                          
                              $id=$rec[‘id’];
                              $pname=$rec[‘name’];
                              $pprice=$rec[‘price’];
                              $qty=$this->input->post(‘qty’);
                          
                          
                            
                          }
                          
                          $this->load->library(‘cart’);
                          $productarray=array(‘id’=>$id,‘pname’=>$pname,‘pprice’=>$pprice,‘qty’=>$qty);
                          
                            print_r($productarray);
                          //$data[‘productarray’]=$productarray;
                          $cartinsert=$this->cart->insert($productarray);
                      
                          
                          
                          $data[‘title’] = ‘Ziplance Lab Hosting Service| Penny auction script | Dating script | Freelance script | Zip Lance Lab | Ziplancer’;
                          $data[‘meta_keywords’] = ‘Excellent Penny auction script, Ziplane lab product list.’;
                          $data[‘meta_description’] = ‘Zip Lance Lab providing excellent product at cheapest rate.’;
                          $data[‘page_req’]=‘shoppinglist’;
                          $this->load->view(‘full_page’,$data);
                      
                  
                    }

Fail: Damn it's still not readable...

It's better to clean your code first... Also use MVC. Breakt down the logic into it's own controller, model and view


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.