I'm trying to get the $data from my controller to go into my view but it does not seem to be working. I keep getting a "variable does not exist" error. Here's the Controller code (view is loaded in a different part).
$affiliate_id = $this->input->get_post('affiliate_id');
$product_id = $this->input->get_post('product_id');
$data = array();
if (empty($affiliate_id)
&& empty($product_id))
{
$this->session->set_flashdata('error', 'Please enter an affiliate ID, a product ID, or both.');
redirect('admin/affiliate_relationship');
}
if (empty($affiliate_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate_by_product_id($product_id);
}
elseif (empty($product_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate_by_affiliate_id($affiliate_id);
$affiliate = $affiliate_id;
}
elseif (!empty($affiliate_id)
&& !empty($product_id))
{
$data['affiliate_relationship'] = $this->AffiliateRelationship->search_for_affiliate($affiliate_id, $product_id);
$affiliate = $affiliate_id . '/';
}
$data['affiliate_id'] = $affiliate_id;
$data['product_id'] = $product_id;
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id, $data);
When I pr($data) I get the array correctly, so I know the data is all there. It's just when it is used in the view it does not even exist.
Am I doing something wrong? I've done other controller and views more-or-less the same way and never got problem this before.
EDIT: View code.
<?php
$affiliateRelationshipRows = NULL;
if (!empty($affiliate_relationship))
{
$class = NULL;
$i = 0;
foreach ($affiliate_relationship->result_array() as $affiliate)
{
if (++$i%2 == 0)
{
$class= ' class="odd"';
}
else
{
$class = NULL;
}
$affiliateRelationshipRows .= <<<END
<tr $class>
<td class="text-left">{$affiliate['id']}</td>
<td class="text-left">{$affiliate['product_id']}</td>
<td class="text-left">{$affiliate['user_id']}</td>
<td class="text-left">{$affiliate['affiliate_status_id']}</td>
<td class="text-left">{$affiliate['created']}</tD>
<td class="text-left">{$affiliate['custom_payout']}</td>
<td class="text-left">{$affiliate['delayed']}</td>
<td class="text-left">{$affiliate['sales_page_url']}</td>
<td class="text-left">{$affiliate['comments']}</td>
</tr>
END;
}
}
?>
<?php echo form_open($this->uri->uri_string()); ?>
<div class="box-search">
<div class="grid-2" style="width:200px; margin-left:25px;">
<span class="label" style="float:none;">
Affiliate ID:
</span>
<span class="field" style="float:none;">
<input type="text" name="affiliate_id" value="<?php if (!empty($affiliate_id)) { echo $affiliate_id; } ?>" style="width: 75px;"/>
</span>
<?php echo form_error('affiliate_id'); ?>
</div>
<div class="grid-2" style="width:200px; margin-left:0px;">
<span class="label" style="float:none; ">
Product ID:
</span>
<span class="field" style="float:none;">
<input type="text" name="product_id" value="<?php if (!empty($product_id)) { echo $product_id; } ?>" style="width:75px;"/>
</span>
<?php echo form_error('product_id'); ?>
</div>
RESET
<input type="submit" name="search" class="btn btn-green btn-mini-submit btn-search" value="SEARCH"/>
<div class="clear"></div>
</div>
<?php echo form_close(); ?>
<div class="box">
<div class="top">
Affiliate Relationship
</div>
<div class="main-table">
<table class="style1" cellpadding="2" cellspacing="0" width="100%" border="0">
<thead>
<tr>
<th>ID</th>
<th>Product ID</th>
<th>User ID</th>
<th>Affiliate Status ID</th>
<th>Created</th>
<th>Custom Payout</th>
<th>Delayed</th>
<th>Sales Page URL</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<?php echo $affiliateRelationshipRows; ?>
</tbody>
</table>
</div>
The array:
Array
(
[affiliate_relationship] => Array
(
[0] => stdClass Object
(
[id] => 11615304
[created] => 2015-09-17 00:00:00
[product_id] => 175538
[user_id] => 393598
[comments] =>
[affiliate_status_id] => 2
[custom_payout] =>
[delayed] => 0
[sales_page_url] =>
)
)
[affiliate_id] => 11615304
[product_id] => 175538
)
I don't think you can send data like that in redirect_and_continue_processing() or redirect() in codeigniter. The only way to do that is by sending the data as an argument to the function that you are trying to redirect to. Then in that function, use the data to generate the view.
LIke :
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id/$data);
And in the method "affiliate_relationship" , accept the argument
Redirect method does not take an argument as the variable to send to view.
instead of using
redirect_and_continue_processing('admin/affiliate_relationship/' . $affiliate . $product_id, $data);
you can use simple way to do this
$this->load->view('your_view_name','your data in array');
Related
I have a site where you can order some tickets. If someone makes an order, I want the order to be send to the database. Also I want to put the specific cart items in to be send to the database. See the model I use:
ORDERS CART ITEMS
id* id
amount order_id*
product_id
quantity
This is the code I use with the form:
<form action="index.php?page=cart" method="post" class="">
<table class=" table__nav">
<thead>
<tr>
<th class="p p--bold p--th th--ticket">Ticket</th>
<th class="p p--bold p--th th--name">Name</th>
<th class="p p--bold p--th th--quantity">Quantity</th>
<th class="p p--bold p--th th--price">Price per ticket</th>
<th class="p p--bold p--th th--itemtotal">Item Total</th>
</tr>
</thead>
<tbody>
<?php
$total = 0;
foreach($_SESSION['cart'] as $ticket) {
$ticketTotal = $ticket['ticket']['price'] * $ticket['quantity'];
$total += $ticketTotal;
?>
<tr>
<td>
<?php echo $ticket['ticket']['eye_cart']; ?>
</td>
<td>
<p class = "p--bold"><?php echo $ticket['ticket']['name']; ?></p>
</td>
<td>
<input class = "p td--quantity" type="number" name="quantity[<?php echo $ticket['ticket']['id'];?>]" value="<?php echo $ticket['quantity'];?>" class="replace" required />
</td>
<td>
<p>€<?php echo $ticket['ticket']['price'];?>,-</p>
</td>
<td>
<p>€<?php echo $ticketTotal;?>,-</p>
</td>
<td>
<td class="remove-item"><button type="submit" class="btn remove-from-cart" name="remove" value="<?php echo $ticket['ticket']['id'];?>">×</button></td>
</td>
</tr>
</tbody>
<?php } ?>
</table>
<div class="table__wrap">
<button type="submit" id="update-cart" class="btn btn--cart" name="action" value="update">
<img width="14" height="14" src="./assets/img/refresh.png" alt="refresh">
</button>
</img>
<p class="table__order--total"><span class="span--bold span--bold-no">Total:</span></p>
<p class="table__order--number"><span class="span--bold span--bold-no">€ <?php echo $total ?>,-</span></p>
</div>
<div class="table__wrap table__wrap--end">
<a class="p p__li p__li--light" href="index.php?page=register">
<button type = "submit" name ="action" value = "details" class="btn btn--big btn--big-2 btn--dark">your details -> </button></a>
</div>
</form>
When the user presses the button to go to "your details" I want to save an order with the total amount + the cart items with the order_id and quantity.
I'm using the MVC model for this but I can't really figure it out.
This is how my controller looks:
if ($_POST['action'] == 'details') {
$data = array(
'amount' => $total,
);
$insertedOrder = $this->orderDAO->insertOrder($data);
$this->set('insertedOrder', $insertedOrder);
if (empty($insertedOrder)) {
$errors = $this->orderDAO->validate($data);
$this->set('errors', $errors);
}
}
if ($_POST['action'] == 'details') {
$dataB= array(
'order_id' => ?,
'product_id' => $_SESSION['cart']['id']['ticket']['id'],
'quantity' => $_SESSION['cart']['quantity'],
);
$insertedCartItem = $this->orderDAO->insertCartItem($data);
$this->set('insertedCartItem', $insertedCartItem);
if (empty($insertedCartItem)) {
$errors = $this->orderDAO->validateB($dataB);
$this->set('errors', $errors);
}
}
And the next code is my DAO:
public function insertOrder($data){
$errors = $this->validate( $data );
if (empty($errors)) {
$sql = "INSERT INTO `orders` (`amount`) VALUES (:amount)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':amount', $data['amount']);
if ($stmt->execute()) {
return $this->selectOrderById($this->pdo->lastInsertId());
}
}
return false;
}
public function insertCartItem($dataB){
$errors = $this->validateB($dataB);
if (empty($errors)) {
$sql = "INSERT INTO `cart_items` (`order_id` `product_id`,`quantity`) VALUES (:order_id, :product_id, :quantity)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':order_id', $dataB['order_id']);
$stmt->bindValue(':product_id', $dataB['product_id']);
$stmt->bindValue(':quantity', $dataB['quantity']);
if ($stmt->execute()) {
return $this->selectCartItemById($this->pdo->lastInsertId());
}
}
return false;
}
The main problem I have is that I don't know how I can send data from $_SESSION variables to the database. I run into problems in the controller. As you can see I'm sending data with the $data and $dataB, but I think I'm going wrong there.
Hey guys can you guys help me with this checkbox problem? If I check the column and press update, I want the update to happen at current time.
this is an example
I want if I check the checkbox and press the update button and the column will update at the current time
This is my view :
<div class="container">
<div class="row">
<div class="col-md-10">
<div class="panel panel-info">
<div class="panel-heading">Setting Jam & Tanggal Mesin</div>
<div class="panel-body">
<table id="devid_auto" class="table table-bordered dt-responsive" cellspacing="0" width="100%">
<thead>
<tr>
<th width="1%" align="center"><input type="checkbox" onClick="toggle(this)" id="checkAll" name="checkAll" /></th>
<th width="10%" align="center">Nama Mesin</th>
<th width="5%" align="center">IP Address</th>
<th width="10%" align="center">SN</th>
<th width="5%" align="center">Ethernet Port</th>
<th width="10%" align="center">Last Update</th>
</tr>
</thead>
<tbody>
<?php
foreach($data as $d){
?>
<tr>
<td><input class="childbox" type="checkbox" name="msg[]" id="id" value="<?php echo $d['devid_auto'] ?>" /></td>
<td class="data-check" ><?php echo $d['device_name']; ?></td>
<td class="data-check" ><?php echo $d['ip_address']; ?></td>
<td class="data-check" ><?php echo $d['sn']; ?></td>
<td class="data-check" ><?php echo $d['ethernet_port']; ?></td>
<td class="data-check" ><?php echo $d['lastupdate_date']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="form-group">
<label for="colFormLabelLg" class="col-sm-3 col-form-label col-form-label-lg">Tanggal & Waktu Sekarang</label>
<div class="col-sm-3">
<input type="" class="form-control" id="" value="<?php date_default_timezone_set("Asia/Jakarta"); echo date(" Y-m-d H:i:s ");?>"" readonly>
</div>
</div>
</div>
<div class="panel-footer text-right">
<button allign="center" class="btn btn-danger" onclick="update()">Update Date and time</button>
</div>
</div>
<script src="<?php echo base_url() ?>assets/baru/jquery-3.2.1.min.js"></script>
<script src="<?php echo base_url() ?>assets/baru/jquery.dataTables.min.js"></script>
<script src="<?php echo base_url() ?>assets/baru/dataTables.bootstrap4.min.js"></script>
<script type="text/javascript">
$(document).ready( function ()
{
$('#devid_auto').DataTable();
$("input[name='checkAll']").click(function() {
var checked = $(this).attr("checked");
$("#devid_auto tr td input:checkbox").attr("checked", checked); });
});
function toggle(id)
{
checkboxes = document.getElementsByName('msg[]');
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = id.checked;
}
}
function update(id)
{
var list_id = [];
$("#id:checked").each(function() {
list_id.push(parseInt(this.value));
});
console.info(JSON.stringify(list_id));
if(list_id.length > 0)
{
if(confirm('Are you sure update this '+list_id.length+' data?'))
{
$.ajax({
type: 'POST',
data: {'devid_auto': list_id},
url: '<?php echo site_url('setting/mesin_update')?>',
success: function(result)
{
var hasil = result.replace(/\s/g,'');
if(hasil == 'y')
{
alert("Data Berhasil di Update");
location.reload();
}
else
{
alert('Failed.');
}
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error update data');
}
});
}
}
else
{
alert('no data selected');
}
}
</script>
</div><!-- end cols-->
</div><!--end row-->
</div> <!-- end container-->
and this is my controller :
public function mesin_update()
{
$initiated_date = date('Y-m-d H:i:s');
$data = array(
'lastupdate_date' => $initiated_date,
);
$devids = $this->input->post('devid_auto', True);
foreach($devids as $devid){
$this->Jam_tgl_model->jam_tanggal_update(array('devid_auto' => $devid ), $data);
}
echo 'y';
}
and this is my model :
public function jam_tanggal_update($where, $data)
{
$this->db->update($this->table, $data, $where);
return $this->db->affected_rows();
}
I have tried it with my code but nothing has changed on column last update date
please help fix my code so i can finish it
( NEW EDIT) :
- this is the result:
- I checked the line
- and pressing the update button, can you change the script function update (id)?
- and this is the result after I hit update button
in contorller
$devids = $this->input->post('devid_auto', True);
foreach($devids as $devid){
$this->Jam_tgl_model->jam_tanggal_update(array('devid_auto' => $devid), $data);
}
NOTE: also you can use ci $this->db->update_batch()
Try this in your model
public function jam_tanggal_update($where, $data) {
$this->db->where($where);
$this->db->update($this->table_dept, $data);
return $this->db->affected_rows();
}
For More details on Updating: See CodeIgniter official documentation
Try This.. This May Help you .
Controller
public function delete_inbox()
{
$ids = ( explode( ',', $this->input->get_post('devid_auto') ));
$initiated_date = date('Y-m-d H:i:s');
$data = array(
'lastupdate_date' => $initiated_date,
);
$del= $this->model-mesin_update($ids,$data);
}
Model:
public function jam_tanggal_update($where, $data){
$ids = $ids;
$count = 0;
foreach ($ids as $id){
$did = intval($id);
$this->db->where('id', $did);
$res=$this->db->update('<table_name',$data);
$count = $count+1;
}
}
I am trying to redirect the page back to general_faq_category route but when it is redirected the data is not loaded correctly. So i manually refresh the page and then the data is loaded correctly (sorted). Why is the page not refreshing automatically? It should load the data sorted but it isn't loading when the below func is executed, however after manually refreshing the route the changes appear.
The following is the code i used for redirecting
Function for sorting data:
function executeFaqCategoryOrder(sfWebRequest $request) {
$faqid = $request->getParameter('faqid');
$direction = $request->getParameter('direction');
if ($faqid & $direction) {
$c = new Criteria();
$c->add(FaqCategoryPeer::ID, $faqid);
$current_faq = FaqCategoryPeer::doSelectOne($c);
$current_order = $current_faq->getOrder();
switch ($direction) {
case 'UP':
$c = new Criteria();
$c->add(FaqCategoryPeer::ORDER, $current_order - 1);
$previous_faq = FaqCategoryPeer::doSelectOne($c);
$current_faq->setOrder($previous_faq->getOrder());
$current_faq->save();
$previous_faq->setOrder($current_order);
$previous_faq->save();
$this->redirect($this->generateUrl('general_faq_category'));
break;
break;
case 'DOWN':
$c = new Criteria();
$c->add(FaqCategoryPeer::ORDER, $current_order + 1);
$next_faq = FaqCategoryPeer::doSelectOne($c);
$current_faq->setOrder($next_faq->getOrder());
$current_faq->save();
$next_faq->setOrder($current_order);
$next_faq->save();
$this->redirect($this->generateUrl('general_faq_category'));
break;
break;
default:
$this->redirect($this->generateUrl('general_faq_category'));
break;
}
$this->redirect($this->generateUrl('general_faq_category'));
}
}
Another Func from actions.php
public function preExecute() {
self::$formName = "FaqCategoryAdminForm";
self::$modelPeer = "FaqCategoryPeer";
self::$model = "FaqCategory";
$this->redirectUrl = 'faq_category/index';
}
View Code:
<div class="pagead">
<div class="pagein"align="center">
<div align="center">
<h3>FAQ Category (Total: <?php echo $total ?>)</h3>
<span style="float: right;">
Back |
New FAQ Category
</span>
</div>
<br/>
<div align="center"><?php $pager->render() ?></div>
<table width="100%" id="category">
<tr>
<th width="30%">Name</th>
<th width="15%">Created At</th>
<th width="5%">Order</th>
<th width="12%">Action</th>
</tr>
<?php foreach ($pager->getResults() as $row): ?>
<tr id="category_<?php echo $row['id'] ?>" class="categories">
<td align="center"><?php echo $row['name']; ?></td>
<td align="center"><?php echo date(sfConfig::get('app_display_alternate_format_for_date'), strtotime($row['created_at'])); ?></td>
<td>
▲
▼
</td>
<td align="center">
<?php echo link_to(image_tag("/images/edit.png", array("title" => "Click to modify category")), $sf_params->get('module') . '/edit?id=' . $row['id']); ?>
<?php echo link_to(image_tag("/images/cross.png", array("title" => "Click to delete category")), $sf_params->get('module') . '/delete?id=' . $row['id'], array('confirm' => 'All related records will be deleted, are you sure ?')); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<br/>
<br/>
</div>
<div class="bot"></div>
I have a page that allows for multiple record deletes using checkboxes and all works fine.
However, each record may have an image associated with it stored in a folder that would also need to be deleted but I have no idea how to achieve this even though I've searched Stackoverflow and Google.
How do I delete the record(s) from the MySQL database and the image(s) associated with it from the folder?
What I have so far is:
The code that deletes the records:
if ( isset( $_POST[ 'chk_id' ] ) ) {
$arr = $_POST[ 'chk_id' ];
foreach ( $arr as $id ) {
#mysqli_query( $KCC, "DELETE FROM pageContent WHERE contentID = " . $id );
}
$msg = "Page(s) Successfully Deleted!";
header( "Location: delete-familyservices.php?msg=$msg" );
}
The form that selects the records to delete:
<form name="deleteRecord" id="deleteRecord" method="post" action="delete-familyservices.php">
<?php if (isset($_GET['msg'])) { ?>
<p class="alert alert-success">
<?php echo $_GET['msg']; ?>
</p>
<?php } ?>
<table width="100%" class="table table-striped table-bordered table-responsive">
<tr>
<th>Page Title</th>
<th>Page Text</th>
<th>Page Image</th>
<th>Delete</th>
</tr>
<?php do { ?>
<tr>
<td width="30%" style="vertical-align: middle">
<h4 style="text-align: left">
<?php echo $row_rsContent['contentTitle']; ?>
</h4>
</td>
<td width="45%" style="vertical-align: middle">
<?php echo limit_words($row_rsContent['contentData'], 10); ?> ...</td>
<td align="center" style="vertical-align: middle">
<?php if (($row_rsContent['contentImage']) != null) { ?>
<img src="../images/<?php echo $row_rsContent['contentImage']; ?>" class="img-responsive">
<?php } else { ?> No Image
<?php } ?>
</td>
<td width="5%" align="center" style="vertical-align: middle"><input type="checkbox" name="chk_id" id="chk_id" class="checkbox" value="<?php echo $row_rsContent['contentID']; ?>">
</td>
</tr>
<?php } while ($row_rsContent = mysqli_fetch_assoc($rsContent)); ?>
</table>
<p> </p>
<div class="form-group" style="text-align: center">
<button type="submit" name="submit" id="submit" class="btn btn-success btn-lg butt">Delete Selected Page(s)</button>
<button class="btn btn-danger btn-lg butt" type="reset">Cancel Deletion(s)</button>
</div>
</form>
The final piece of code, which is a confirmation script:
<script type="text/javascript">
$( document ).ready( function () {
$( '#deleteRecord' ).submit( function ( e ) {
if ( !confirm( "Delete the Selected Page(s)?\nThis cannot be undone." ) ) {
e.preventDefault();
}
} );
} );
</script>
I've seen the unlink() function mentioned but I don't know if this is what to use or have any idea how to incorporate it into the existing code if it is.
you'll have to use the path of the image which is stored on you database like so :
unlink(' the link of the images which is fetched from db'); // correct
don't forget to check for image existence file_exists() //
Got this from another site and a bit of trial and error.
if($_POST) {
$arr = isset($_POST['chk_id']) ? $_POST['chk_id'] : false;
if (is_array($arr)) {
$filter = implode(',', $arr);
$query = "SELECT *filename* FROM *table* WHERE *uniqueField* IN ({$filter})";
$result = mysqli_query(*$con*, $query);
while ($row = mysqli_fetch_object($result)) {
$pathToImages = "*path/to/images*";
{
unlink("{$pathToImages}/{$row->contentImage}");
}
}
// DELETE CAN BE DONE IN ONE STATEMENT
$query = "DELETE FROM *table* WHERE *uniqueField* IN ({$filter})";
mysqli_query(*$con*, $query);
$msg = "Page(s) Successfully Deleted!";
header("Location: *your-page.php*?msg=$msg");
}
}
Thanks to everyone who contributed.
Hope this is of some help to others.
I just created code that deletes an image from database and also from folder which is an image store, but only one image is successfully deleted from thedatabase and folder when I click "check all". What did I do wrong? Here is my view using check box javascript:
<form name="indonesia" action="<?php echo site_url('admin/wallpaper/delete'); ?>" method="post">
<button type="submit" class="btn btn-danger" name="hapus" value="hapus">Hapus</button>
<?php echo anchor('admin/wallpaper/tambah', 'Tambah Wallpaper');?>
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>
<button type="button" class="btn btn-info" onClick="check_all()" >Check</button>
<button type="button" class="btn btn-success" onClick="uncheck_all()" >Un-Check</button>
</th>
<th>id</th>
<th>Keterangan</th>
<th>Gambar</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($ListWallpaper->result() as $row)
{
?>
<tr>
<td><input type="checkbox" name="item[]" id="item[]" value="<?=$row->id_wall ?>"></td>
<td><?=$row->id_wall ?></td>
<td><?=$row->ket ?></td>
<td><?=$row->wall ?></td>
<td>
Delete
Update
</td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
and here is my controller
public function delete()
{
$ownerNames = $this->input->post('item');
foreach ($ownerNames as $ownerName => $k) {
//echo "Array : " . $k . "<br/>";
$photo = $this->wallpaper_model->del_photo($k);
if ($photo->num_rows() > 0)
{
$row = $photo->row();
$file_photo = $row->wall;
echo "$file_name</br>";
$path_file = 'image/wallpaper/';
unlink($path_file.$file_photo);
}
$this->wallpaper_model->drop_photo($k);
redirect('admin/wallpaper','refresh');
}
}
and my model
function del_photo($k)
{
$this->db->where('id_wall',$k);
$query = $getData = $this->db->get('tabel_wall');
if($getData->num_rows() > 0)
return $query;
else
return null;
}
function drop_photo($k)
{
$this->db->where('id_wall',$k);
$this->db->delete('tabel_wall');
}
Only one image is successfully deleted from the folder and database too, but when I try to echo "$file_name</br>"; it show all images. What did I do wrong? if anyone can guide me, I will appreciate that.
First off I would set a array of images from controller to view, $data['wallpapers'] = array(); for some of the site_url you may need to include in your route.php $route['controller/update/(:any)'] = "controller/update/$1"
To Delete selected images, You could do a selected post in array() and then on the value check box name=""
Disclaimer: This is just for a example only.
public function index() {
$k = $this->uri->segment(what ever); // Use uri segment is id example.com/image/1 = $this->uri->segment(2);
$results = $this->model_name->del_photo($k);
$data['wallpapers'] = array();
foreach ($results as $result) {
$data['wallpapers'][] = array(
'id_wall' => $result['id_wall'],
'update' => site_url('controllername/update' .'/'. $result['wall_id']),
'ket' => $result['ket']
);
}
$data['delete'] = site_url('controller/function');
$selected = $this->input->post('selected');
if (isset($selected)) {
$data['selected'] = (array)$selected;
} else {
$data['selected'] = array();
}
$this->load->view('your list', $data);
}
public function update() {
//update info here
}
public function delete() {
$selected = $this->input->post('selected');
if (isset($selected)) {
foreach ($selected as $image_id) {
$wall_id = $image_id
$this->db->query("DELETE FROM " . $this->db->dbprfix . "TABLENAME WHERE wall_id = '" . (int)$wall_id . "'");
}
}
}
View
Added echo delete from controller as site url.
<form action="<?php echo $delete;?>" method="post">
<table>
<thead>
<tr>
<td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
<td>Update</td>
</tr>
</thead>
<tbody>
<?php if ($wallpapers) { ?>
<?php foreach ($wallpapers as $wallpaper) { ?>
<td class="text-center"><?php if (in_array($wallpaper['id_wall'], $selected)) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $wallpaper['id_wall']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $wallpaper['id_wall']; ?>" />
<?php } ?>
</td>
<td>Update</td>
<?php } ?>
<?php } ?>
</tbody>
</table>
</form>
Model
function del_photo($k) {
$this->db->where('id_wall',$k);
$query = $this->db->get('table_name');
if($query->num_rows() > 0) {
$return = $query->result_array();
} else {
return false;
}
}
In controller, move redirect directive outside of foreach loop.