store session cart to database - codeigniter

Sorry for asking this old questions, and I know that I've read before I ask here, it's can use database for adding more cart without limitation. I already try to use ci_sessions table to store session but still no luck, I only can adding 6 items maximum.
please help me, I looking for some example for this almost two days and result is nothing
EDITED
this is my view
<table id="box-table-a" summary="Employee Pay Sheet">
<thead>
<tr>
<th scope="col">Description</th>
<th scope="col">Price</th>
<th class="centered" scope="col">Options</th>
</tr>
</thead>
<tbody>
<?php foreach ($foto_produk->result() as $key => $value) {?>
<tr>
<td><?php echo $value->description;?></td>
<td><?php echo $value->price;?></td>
<td class="centered"><input type="checkbox" name="produk_foto[]" value="<?php echo $value->id;?>" /></td>
</tr>
<?php }?>
</tbody>
</table>
here's my controller code
if($this->input->post('produk_foto')){
$id_foto = $this->input->post('produk_foto');
foreach ($id_foto as $key => $value) {
$this->db->where('id', $value);
$query = $this->db->get('foto_product');
if($query->num_rows() > 0){
foreach($query->result() as $ids => $rows){
echo $rows->id.'<br />';
$data_produk = array(
'user_data'=> array(
'id' => $rows->id,
'price' => $rows->price,
'name' => $rows->description,
'qty' => $rows->aantal
)
);
$this->cart->insert($data_produk);
}
}
}
}
and this my view code
<?php if(!$this->cart->contents()):?>
<div class="alert-box warning">The regular products are empty.</div>
<div class="clearfix"></div>
<?php else:?>
<hr>
<h4>REGULAR PRODUCTS</h4>
<div class="order_detail" id="Display">
<table>
<thead>
<tr>
<th>DESCRIPTION</th>
<th>QUANTITY</th>
<th>PRICE PER ITEM(S)</th>
<th>TOTAL</th>
<th>REMOVE</th>
</tr>
</thead>
<tbody>
<?php foreach($this->cart->contents() as $rows):?>
<tr>
<td style="font-weight:bold;"><?php echo $rows['name'];?></td>
<td>
<?php echo form_open(current_url());?>
<input type="text" size="3" name="quantity" value="<?php echo $rows['qty'];?>" />
<input type="hidden" size="3" name="rowid" value="<?php echo $rows['rowid'];?>" />
<input type="submit" name="update" value="Update" />
<?php echo form_close();?>
</td>
<td><?php echo $rows['price'];?></td>
<td><?php echo $this->cart->format_number($rows['subtotal']);?></td>
<td>delete</td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<td colspan="3">Total Products</td>
<td colspan="3">€ <?php echo $this->cart->format_number($this->cart->total());?></td>
</tr>
<tr>
<td colspan="3">Total Shipping</td>
<td colspan="3"></td>
</tr>
<tr>
<td colspan="3"></td>
<td colspan="3" style="padding:0;text-align:center;">
<p>TOTAL :</p>
<span class="tot">€ <?php echo $this->cart->format_number($this->cart->total());?></span>
</td>
</tr>
</tfoot>
</table>
</div>
<?php endif;?>
with this code I want to insert using checkbox with array, and I have more than 6 checkbox
thank you in advance

Ok it's solved by my self..
I don't know that in the name of product there are special characters..
and shame of me..
but thank you anyway

Related

Is there a way to send array of textbox and checbox from View To Controller (CodeIgniter)

I am building a store front with CodeIgniter where list of items from the database is displayed with a checkbox in the View. The user is to select items and enter their quantity. When the user Click Send, the list of Items and their quantity that user set will be submitted to the Database.
Here is the View Code:
<table>
<thead>
<tr>
<th>SN</th>
<th>Product</th><th>Tick</th>
<th>quantity</th>
</tr>
</thead>
<tbody>
<?php
$i=0;
foreach($it as $r):
$i++;
?>
<tr><td><?php echo $i; ?></td>
<td><?=$r['Item'];?></td>
<td>
<input type="checkbox" name="item[]" value="<?=$r['Item']?>" /></td>
</td>
<td>
<input type="number" name="qty[]" />
</td>
</tr> <?php endforeach?>
<tr><td colspan="3">
<input type="submit" name="btnub" value="Send Order" /></td></tr>
</tbody>
</table>
<!-- Controller Code (CodeIgniter) -->
<!-- CodeIgniter Controller Code to harvest the Order -->
if (isset($_POST['btnub'])) {
foreach($_POST['item'] as $key=>$item) {
for ($i = 1; $i < 2000; $i++) {
$h = "qty" . $i;
$qty = $this->input->post[$h];
}
$tt = array(
'item' => $item,
'Qty' => $qty,
);
$this->tranmodel->insertthing("cuzorder", $tt);
} }

how to parse field value without parsing record id with codeigniter

In my database one project has many tasks. I was able to give the edit option for each record by parsing the record id when the update button is clicked. But as one project has many task now I need to parse the projectname when the button clicked and show all the tasks related to that project. Can Somebody help me?
This is the button with record
This is the code
<table class="table table-lg">
<thead >
<tr class="filters">
<th class="col-lg-1"><input type="text" class="form-control" placeholder="Project" disabled></th>
<th class="col-lg-1"><input type="text" class="form-control" placeholder="Client" disabled></th>
<th class="col-lg-1"><input type="text" class="form-control" placeholder="Task " disabled></th>
<th class="col-lg-1"><input type="text" class="form-control" placeholder="Description" disabled></th>
<th class="col-lg-2"><input type="text" class="form-control" placeholder="Create Date and Time" disabled></th>
<th class="col-lg-2"><input type="text" class="form-control" placeholder="Start Date and Time" disabled></th>
<th class="col-lg-2"><input type="text" class="form-control" placeholder="Due Date and Time" disabled></th>
<th class="col-lg-1"> Edit</th>
<th class="col-lg-1"> Delete</th>
</tr>
</thead>
<tbody>
<?php
if(isset($view_data) && is_array($view_data) && count($view_data)): $i=1;
foreach ($view_data as $key => $data) {
?>
<tr <?php if($i%2==0){echo 'class="even"';}else{echo'class="odd"';}?>>
<td><?php echo $data['projectname']; ?></td>
<td><?php echo $data['cname']; ?></td>
<td><?php echo $data['mytext']; ?></td>
<td><?php echo $data['mytext1']; ?></td>
<td><?php echo $data['mytext2']; ?></td>
<td><?php echo $data['mytext3']; ?></td>
<td><?php echo $data['mytext4']; ?></td>
<td><?php echo $data['mytext5']; ?></td>
<td><a class="btn btn-warning" role="button" href="<?php echo site_url('Task/edit_data/'. $data['id'].''); ?>"><i class="glyphicon glyphicon-pencil"></i> Edit</a></td>
<td><a type="button" class="btn btn-danger" href="<?php echo site_url();?>/Task/delete_data/<?php print($data['id']);?>">
<img src='' title="Delete" onClick="return doconfirm();" />
</a></td>
</tr>
<?php
$i++;
}
else:
?>
<tr>
<td colspan="7" align="center" >No Records Found..</td>
</tr>
<?php
endif;
?>
</tbody>
</table>

how to update cart quantity in CodeIgniter?

I want to update the quantity of a shopping cart. I've google it a lot but couldn't do it.
Maximum pages are showing which i don't want. Exactly solution i'm not getting. Hopefully i will get here. Please help me to do it. Here is my view page.
**<table class="table table-hover table-bordered table-striped snipcart-details "> <thead>
<tr>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Delete Cart</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Product Name</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Image</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Price</th>
<th style="color:#FF0033; font-weight:bolder; text-align:center;" >Quantity</th>
<th colspan="2" style="color:#FF0033; font-weight:bolder; text-align:center;" >Total</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->cart->contents() as $items) { ?>
<tr>
<td style="color:#000000; font-weight:bolder; text-align:center;" >
<a href="#" class="remove_cart" title="delete" row_id="<?php echo $items['rowid']; ?>" rel="1">
<i class="fa fa-times fa-2x" style="color:red;" aria-hidden="true"></i> </a></td>
<td style="color:#000000; font-weight:bolder; text-align:center;" ><?php echo $items['name']; ?></td>
<td align="center"><img src="<?php echo base_url('resource/allproduct/'.$items['productImage']);?>" height="50px;" /></td></td>
<td style="color:#000000; font-weight:bolder; text-align:center;"><?php echo $items['price']; ?></td>
<td align="center"><input type="number" name="qty" id="qty" value="<?php echo $items['qty']; ?>"></td>
<td colspan="2" style="color:#000000; font-weight:bolder; text-align:center;">TK <?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php } ?>
</tbody>
<tbody>
<tr>
<th scope="row"> <input type="button" name="submit" value="Update" class="button" /> </th>
<td align="center"> <input type="button" name="submit" value="Continue Shopping" class="button" /></td>
<td colspan="3" class="button" align="center" >
<?php if(!empty($userid)){?>
<input class="button" type="submit" value="Place Order">
<?php } else {?>
<input class="button" type="submit" value="Place Order">
<?php }?>
</td>
<td align="center" style="color:#000000;" > <h4>Grand Total</h4> </td>
<td style="font-size:24px; font-weight:800; color:green;">TK <?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</tbody>
</table>**
And here is controler.
public function index()
{
$data['basicinfo'] = $this->M_cloud->basicall('basic_info');
$where = array('status' => 1);
$data['categoryinfo'] = $this->M_cloud->categoryinfo('item_manage', $where);
$data['rows'] = count($this->cart->contents());
$data['userid'] = $this->session->userdata('user_id');
$data['subcategoryinfo'] = $this->M_cloud->findAll2('sub_category', array('status' => 1));
$data['menuinformation'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 2), 'menuname asc');
$data['menuservice'] = $this->M_cloud->findReport('our_service', array('serviceType'=> 1), 'menuname asc');
$data['socialmedia'] = $this->M_cloud->findAll('social_tbl', 'name asc');
$data['newsinfo'] = $this->M_cloud->findAll('news_table', 'newstitle DESC');
$this->load->view('cartPage', $data);
}
public function buy()
{
$proId = $this->input->post('proId');
$Qty = $this->input->post('Qty');
$prosize = $this->input->post('prosize');
$result = $this->M_cloud->find('product_manage', array('proid' => $proId));
$data2 = array(
'id' => $proId,
'qty' => $Qty,
'name' => $result->proName,
'price' => $result->price,
'prosize' => $prosize,
'productImage' => $result->proimg1,
'product_code' => $result->procode
);
$this->cart->insert($data2);
redirect('cart');
}
public function deleteCartItem() {
$row_id = $this->input->post('row_id');
$data = array(
'rowid' => $row_id,
'qty' => 0
);
$this->cart->update($data);
}
Please help me how to update cart quantity. Thanks in Advance.
To update cart Item :
function updateCartItem(){
$data=array(
'rowid'=>$this->input->post('rowid',TRUE),
'qty'=> $this->input->post('quantity',TRUE)
);
if ($this->cart->update($data)) {
echo "Success";
}else{
echo "Faliure";
}
}
To remove the item from cart :
function deleteCartItem(){
$row_id = $this->input->post('row_id',TRUE);
if ($rowid) {
return $this->cart->remove($rowid);
}
}

Edit Pages - Invalid argument supplied for foreach()

I wonder why I still having this error message appearing.
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/editpages.php
Line Number: 48
Backtrace:
File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\admin\views\editpages.php
Line: 48
Function: _error_handler
controllers/Cpages.php
public function editpagesupdate() {
$data['pagessuccess'] = '';
$pages_id = $this->uri->segment(3);
$data['pages'] = $this->Mpages->update_pages($pages_id);
$this->load->view('editpages', $data);
}
models/Mpages.php
public function update_pages($pages_id)
{
$data = array(
'pages_name' => $this->input->post('pages_name'),
'create_date' => $this->input->post('create_date'),
'pages_order' => $this->input->post('pages_order'),
'pages_content' => $this->input->post('pages_content')
);
$this->db->where('pages_id', $pages_id);
$query = $this->db->update('pages', $data);
//return $query->result_array();
return $query;
}
views/editpages.php
<div class="widget-box">
<div class="widget-title"><h5>Pages</h5></div>
<div class="widget-content">
<?php echo form_open('cpages/editpagesupdate'); ?>
<table border="0" style="width: 100%; height: 90px;">
<tr>
<td>Pages Name</td>
<td><input type="text" name="pages_name" value="<?php echo $pages_item['pages_name']; ?>"></td>
</tr>
<tr>
<td>Create Date</td>
<td><input type="text" name="create_date" value="<?php echo $pages_item['create_date']; ?>"></td>
</tr>
<tr>
<td>Order</td>
<td><input type="text" name="pages_order" value="<?php echo $pages_item['pages_order']; ?>"></td>
</tr>
<tr>
<td>View Content</td>
<td><textarea rows="3" cols="20" name="pages_content"><?php echo $pages_item['pages_content']; ?></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" class="edit" name="submit" value="SUBMIT"></td>
</tr>
</table>
</div>
</div>
<?php endforeach; ?>
controllers/Cpages.php
public function editpagesupdate() {
$data['pagessuccess'] = '';
$pages_id = $this->uri->segment(3);
$update = $this->Mpages->update_pages($pages_id);
$data = array();
/* get updated pages here */
if($update){
$data['pages'] = $this->Mpages->get_pages();
}
$this->load->view('editpages', $data);
}
models/Mpages.php
public function get_pages()
{
$query = $this->db->get('pages');
return $query->result_array();
}
views/editpages.php
<div class="widget-box">
<div class="widget-title"><h5>Pages</h5></div>
<div class="widget-content">
<?php echo form_open('cpages/editpagesupdate'); ?>
<table border="0" style="width: 100%; height: 90px;">
<?php foreach($pages as $pages_item) : ?>
<tr>
<td>Pages Name</td>
<td><input type="text" name="pages_name" value="<?php echo $pages_item['pages_name']; ?>"></td>
</tr>
<tr>
<td>Create Date</td>
<td><input type="text" name="create_date" value="<?php echo $pages_item['create_date']; ?>"></td>
</tr>
<tr>
<td>Order</td>
<td><input type="text" name="pages_order" value="<?php echo $pages_item['pages_order']; ?>"></td>
</tr>
<tr>
<td>View Content</td>
<td><textarea rows="3" cols="20" name="pages_content"><?php echo $pages_item['pages_content']; ?></textarea></td>
</tr>
<?php endforeach; ?>
<tr>
<td></td>
<td><input type="submit" class="edit" name="submit" value="SUBMIT"></td>
</tr>
</table>
</div>
</div>

Adding student in only specific class list using codeigniter

I have a problem in viewing only a class list that I choose and add student but when I select other class it will also appear/view that I select in previous class
here I select the class that I select
Here is the class page that I select and then I add student
but when I choose another class it will also appear the student
here is my controller:
public function viewspecificclass($id)
{
if($this->session->userdata('logged_in'))
{
$this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
$this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
$this->output->set_header('Pragma: no-cache');
$session_data = $this->session->userdata('logged_in');
$data['Username'] = $session_data['Username'];
$row=$this->model_adminlogin->getonerowclass($id);
$data['r']=$row;
$data['classid'] = $id;
$this->load->view('individualviewclass',$data);
} else{
redirect('welcome', 'refresh');
}
if((!isset($session_data) || $session_data !=TRUE)) {
redirect('welcome', 'refresh');
}
}
public function addstudentnow($classid, $studentid){
$data= array(
'ClassId'=>$classid,
'Id'=> $studentid
);
$this->db->insert('enroll',$data);
$this->session->set_flashdata('category_success', 'Successfully Add!');
redirect('enrollment/viewspecificclass ');
}
here is my model:
function statusofenrollment(){
$this->db->select('*');
$this->db->from('studentinformation');
$this->db->join('statusofenrollment', 'statusofenrollment.Id = studentinformation.Id', 'left');
$query = $this->db->get();
return $query->result();
}
function studentinclasslist(){
$this->db->select('*');
$this->db->from('statusofenrollment');
$this->db->join('studentinformation', 'studentinformation.Id = statusofenrollment.Id', 'right');
$this->db->join('enroll', 'enroll.Id = studentinformation.Id', 'right');
$query = $this->db->get();
return $query->result();
}
here is the view:
<div class="z table-responsive">
<table class=" table table-striped ">
<thead>
<tr>
<th class="text-center">LRN</th>
<th class="text-center">First name</th>
<th class="text-center"> Middle name</th>
<th class="text-center">Last name</th>
<th class="text-center">Gender</th>
<th class="text-center">Status of Enrollment</th>
<th class="text-center"> </th>
</tr>
</thead>
<?php
foreach($this->model_adminlogin->studentinclasslist() as $row){
?>
<tr>
<td class="text-capitalize text-center"><?php echo $row->Idnumber ?></td>
<td class="text-capitalize text-center"><?php echo $row -> Firstname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Middlename ?></td>
<td class="text-capitalize text-center"><?php echo $row->Lastname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Sex ?></td>
<td class="text-capitalize text-center"><?php echo $row->Statusofenrollment ?></td>
<td class="text-capitalize text-center">
</td>
</tr>
<?php
}
?>
</table>
</div>
<div id="myModalpick" class="modal fade" role="dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title text-center">Student Status</h4>
</div>
<div class="modal-body">
<div class="z table-responsive">
<table class=" table table-striped ">
<thead>
<tr>
<th class="text-center">LRN</th>
<th class="text-center">First name</th>
<th class="text-center"> Middle name</th>
<th class="text-center">Last name</th>
<th class="text-center">Gender</th>
<th class="text-center">Status of Enrollment</th>
<th class="text-center"> </th>
</tr>
</thead>
<?php
foreach($this->model_adminlogin->statusofenrollment() as $row){
?>
<tr>
<td class="text-capitalize text-center"><?php echo $row->Idnumber ?></td>
<td class="text-capitalize text-center"><?php echo $row -> Firstname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Middlename ?></td>
<td class="text-capitalize text-center"><?php echo $row->Lastname ?></td>
<td class="text-capitalize text-center"><?php echo $row->Sex ?></td>
<td class="text-capitalize text-center"><?php echo $row->Statusofenrollment ?></td>
<td class="text-capitalize text-center">
Add To Class List
</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" >Ok</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
because of the fact that your code is totally unorganized it makes hard to help you - but i'll give it a shot
first of all in your models Function studenClassList you've to pass an id from the specific class because other wise you'll get on any request the students of all of your classes - change your model like this
function studentinclasslist($classId){
$query = $this->db
->select('studentinformation.*')
->from('statusofenrollment')
->join('studentinformation', 'studentinformation.Id = statusofenrollment.Id', 'right')
->join('enroll', 'enroll.Id = studentinformation.Id', 'right')
->where("class.Id",$classId)
->get();
return $query->result();
}
be aware that you have to change in the where construct the actual class.Id field because i wasn't able to see where it is
and after that in your view simply pass the ID to your model function
foreach($this->model_adminlogin->studentinclasslist($classId) as $row){
but in any case i must say, in my opinion it isn't a good idea in CI to use a model in your view because the controller should pass the prepared model data to the view

Resources