<div class="float-right">
<form>
<div class="form-group row">
<div class="col-sm-12">
<select class="form-control" id="select_id" >
<option> Choose Class </option>
#foreach($allclass as $classs)
<option value="{{$classs->id}}"> {{$classs->class}} </option>
#endforeach
</select>
</div>
</div>
</form>
</div>
This is Where user choose Class and when user choose the class i want to view data as per the class .
class SectionController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index(Clas $clas)
{
$allclass = Clas::all();
$sections = $clas->sections;
return view('admin.section.index')
->with('i',$i = 1)
->with('sections',$sections)
->with('allclass',$allclass);
}
This is my section Controller
public function clas(){
return $this->belongsTo(Clas::class);
}
This is Section Model where i keep realtion between clas and section .
public function up()
{
Schema::create('sections', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('section');
$table->string('category');
$table->string('capacity');
$table->integer('clas_id');
$table->integer('teacher_id');
$table->text('note');
$table->softDeletes();
$table->timestamps();
});
}
This is my sectios db .
<table id="userTable" class="table table-bordered table-striped table-vcenter js-dataTable-full-pagination">
<thead>
<tr>
<th class="text-center">S.n</th>
<th class="d-none d-sm-table-cell">Section</th>
<th class="d-none d-sm-table-cell">Category</th>
<th class="d-none d-sm-table-cell">Capacity</th>
<th class="d-none d-sm-table-cell">Teacher Name</th>
<th class="d-none d-sm-table-cell">Note</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
#foreach($sections as $s)
<tr id="table-data">
<td class="d-none d-sm-table-cell" width="8%">{{1}}</td>
<td class="d-none d-sm-table-cell" width="15%">{{$s->section}}</td>
<td class="d-none d-sm-table-cell" width="15%"> {{$s->category}}</td>
<td class="d-none d-sm-table-cell" width="15%"> {{$s->capacity}}</td>
<td class="d-none d-sm-table-cell" width="15%">
{{$s->teacher->user->name}}
</td>
<td class="d-none d-sm-table-cell" width="15%"> {{$s->note}}</td>
<td class="d-none d-sm-table-cell" width="20%">
<form class="" action="{{ route('section.destroy',$s->id) }}" method="post">
#csrf
#method('DELETE')
<a href="{{$s->trashed()?route('section.restore',$s->id):route('section.edit',$s->id)}}">
<button type="button" class="btn btn-warning mr-5 mb-5 " title="{{ $s->trashed()?'Recover':'Edit'}}">
<i class="{{$s->trashed()?'fa fa-recycle':'fa fa-edit'}}"></i>
</button>
</a>
<button type="submit" class="btn btn-danger mr-5 mb-5" title="{{ $s->trashed()?'Delete':'Trash'}}">
<i class="{{$s->trashed()?'fa fa-trash':'fa fa-minus-circle'}}"></i>
</button>
</form>
</td>
</tr>
#php $i++ #endphp
#endforeach
</tbody>
</table>
This is my table for viewing section only when class is selected .
how can i View sections only when some class is selected .
Sorry For my english .
Now I want to view section only when class is selected. How can i do that ?
$('#select_id').change(function(){
// alert('hello');
var cid = $(this).val();
if(cid){
$.ajax({
dataType: "json",
url: 'getSectionsForClass'+cid,
type:"GET",
success: function(response){
console.log (Object.values(response).length);
$('#userTable tbody').empty(); // Empty <tbody>
if(response != null){
var len = Object.values(response).length;
}
$.each(response,function(key,value){
// $("#section_id").append('<option value="'+key+'">'+value+'</option>');
console.log(key,value);
});
if(len >0){
for(var i=0; i<len; i++){
var section = response[i].section;
var capacity = response[i].capacity;
var category = response[i].category;
var teacher = response[i].teacher_id;
var note = response[i].note;
var tr_str = "<tr>" +
"<td align='center'>" + (i+1) + "</td>" +
"<td align='center'>" + section + "</td>" +
"<td align='center'>" + capacity + "</td>" +
"<td align='center'>" + category + "</td>" +
"<td align='center'>" + teacher + "</td>" +
"<td align='center'>" + note + "</td>" +
"<td align='center'><button type='submit' class='btn btn-danger mr-5 mb-5'>" + + "</td>" +
"</tr>";
$("#userTable tbody").append(tr_str);
}
}else{
var tr_str = "<tr>" +
"<td align='center' >No record Availasb.</td>" +
"</tr>";
$("#userTable tbody").append(tr_str);
}
},error: (error) => {
console.log(JSON.stringify(error));
}
});
}
});
public function getSectionsForClass(Request $request ,$id )
{
$section = Section::all()->where('clas_id',$id);
return response()->json($section);
}
I have added some ajax but its only show first class when I choose another class it shows an error
Related
I'm processing the incoming data with Ajax as follows. But I can't make it compatible with dataTable. I've read the Datatable Ajax documentation. But I was never successful. How do I pull the following data into the dataTable? I want to make these codes compatible for Data Table.
You can see multiple parse operations in my code. Please do not warn about it. Net Core, I can only process the JSON file in this way. The only thing I want from you is to show this data that I have processed successfully in the datatable.
<div class="card" id="view-maincategorylist">
<div class="card-body">
<div class="table-responsive">
<table id="datatablex" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th class="text-center">Fotoğraf</th>
<th class="text-center">Ana Kategori Adı</th>
<th class="text-center">Seçenekler</th>
<th class="text-center">İşlemler</th>
</tr>
</thead>
<tbody id="table-maincategories">
</tbody>
</table>
</div>
</div>
</div>
<script>
function GetMainCategoryList() {
$.ajax({
url: "/Admin/BusinessCategories/MainCategories/",
contentType: "application/json",
dataType: "json",
type: "Get",
success: function (data) {
var item = jQuery.parseJSON(data);
$("#table-maincategories").empty();
$.each(JSON.parse("[" + item + "]"), (index, value) => {
for (let element of value) {
$("#table-maincategories").append(`<tr class="text-center">
<td><img src="${element.Image}" style="height:80px;" /></td>
<td>${element.Name}</td>
<td>
<div class="form-check">
<a href="/Admin/BusinessCategories/MainShowMenu/${element.Id}" onclick="location.href=this.href;">
<input class="form-check-input" type="checkbox" id="flex_${element.Id}">
</a>
<label class="form-check-label" for="flex_${element.Id}">Menüde Göster</label>
</div>
</td>
<td>
<a onclick="ShowEditMainCategory(${element.Id})" class="btn btn-primary"><i class="bx bx-edit"></i> Düzenle</a>
<a onclick="DeleteMainCategory(${element.Id});" data-name="${element.Name}" id="del_${element.Id}" class="btn btn-danger delete-button"><i class="bx bx-trash"></i> Sil</a>
</td> </tr>`);
var checkbox = document.getElementById('flex_' + element.Id);
if (element.ShowMenu == true) {
checkbox.checked = true;
}
else {
checkbox.checked = false;
}
}
});
$('#datatable').DataTable();
ViewShowHide(1);
},
error: function () {
Swal.fire('Veriler Okunamadı!', '', 'error')
}
})
}
</script>
Problem Images:
image 1
image 2
image 3
JSON Data Output:
https://easyupload.io/1bsb75
Hi I am trying to set up a table with parent and child data which can be sorted by using the jquery sortable library, I am able to get the position and the respective ids of the data but unable to send the to the controller using jquery
HTML Part:
<tbody class="sort">
#foreach($menus as $menu)
<tr id = "{{ $menu->id }}" class="parent">
<td>{{$menu->name}}</td>
<td>{{ $menu->link }}</td>
#if($menu->sub == 1)
<td>Active</td>
#else
<td>In-Active</td>
#endif
<td class="text-right" >
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="{{$menu->id}}" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
#if(count(App\Menu::where('parent_id',$menu->id)->orderBy('position','asc')->get())>0)
#foreach(App\Menu::where('parent_id',$menu->id)->orderBy('position','asc')->get() as $child)
<tr id="{{ $child->id }}">
<td>~{{$child->name}}</td>
<td>{{ $child->link }}</td>
<td></td>
<td class="text-right" >
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="{{$child->id}}" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
</tr>
#endforeach
#endif
</tr>
#endforeach
</tbody>
Jquery part:
$(document).ready(function(){
$('.sort').sortable({
stop:function(event, ui){
var parameter = new Array();
var position = new Array();
$('.sort>tr').each(function(){
parameter.push($(this).attr("id"));
});
$(this).children().each(function(index) {
position.push(index + 1);
});
$.ajax({
url:"{{ route('menu.savePosition') }}",
method:"POST",
data:{"id":parameter,"position":position},
success:function(response){
console.log(response);
},
error:function(xhr,response){
console.log(xhr.status);
}
});
},
}).disableSelection();
});
Controller Part:
public function SavePosition(Request $req){
$position = ($req->all());
return $req->all();
// foreach($file as $pos){
// $id = $pos[1];
// $position = $pos[0];
// $menu = Menu::findOrFail($id);
// $menu->position = $position;
// $menu->save();
// }
}
After all this the console looks like the following :
please help me out fixing the issue
any help would be highly appreciated
Thanks in advance
Consider the following example.
$(function() {
$(".sort").sortable({
items: "> tbody > tr",
stop: function(event, ui) {
var parameter = $(this).sortable("toArray");
var position = [];
$.each(parameter, function(index, value) {
position.push(index + 1);
});
console.log(parameter, position);
$.ajax({
url: "{{ route('menu.savePosition') }}",
method: "POST",
data: {
"id": parameter,
"position": position
},
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.log(status, error);
}
});
}
});
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" integrity="undefined" crossorigin="anonymous">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="container">
<table class="sort" width="340">
<thead>
<tr>
<th>Name</th>
<th>Link</th>
<th>Status</th>
<td></td>
</tr>
</thead>
<tbody>
<tr id="item-1">
<td>Item 1</td>
<td>Link 1</td>
<td>Active</td>
<td class="text-right">
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="item-1" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
</tr>
<tr id="item-2">
<td>Item 2</td>
<td>Link 2</td>
<td>Active</td>
<td class="text-right">
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="item-2" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
</tr>
<tr id="item-3">
<td>Item 3</td>
<td>Link 3</td>
<td>Active</td>
<td class="text-right">
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="item-3" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
</tr>
<tr id="item-4">
<td>Item 4</td>
<td>Link 4</td>
<td>Active</td>
<td class="text-right">
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="item-4" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
</tr>
<tr id="item-5">
<td>Item 5</td>
<td>Link 5</td>
<td>Active</td>
<td class="text-right">
<i class="fe-edit-2" ></i>
<button data-toggle="tooltip" data-placement="top" data-id="item-5" title="" data-original-title="Delete" class="delete btn btn-danger ml-1 " type="submit"><i class="fas fa-trash-alt"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
It's not clear why you are sending the position as the Array of items will already be in the order of the items. I did include it just in case you do need it for something else.
It's easier to use the toArray method: https://api.jqueryui.com/sortable/#method-toArray You will also want to properly define the items so that Sortable knows what the items should be.
Try this way.
$('#element').sortable({
axis: 'y',
update: function (event, ui) {
var data = $(this).sortable('serialize');
// POST to server using $.post or $.ajax
$.ajax({
data: data,
type: 'POST',
url: '/your/url/here'
});
}
});
I have a function where I can add rows using my button. My target is when the user enters a number that is already on the database, the alert will pop up or any error messages that will say "The number/s you entered is/are already used, please use another number"**. Is there a way where I can make it work? I provided my screenshot and my codes below. Thank you
Views:
<table class="table table-bordered" border="1" id="applicanttable">
<thead>
<tr>
</tr>
</thead>
<tbody>
<div class="row">
<tr>
<th>#</th>
<th>Light</th>
<th>Action</th>
</tr>
<tr id="row_0">
<td>
<input id="#" name="#" class="auto_num" type="text" value="1" readonly />
</td>
<td class="labelcell">
<input value="" class="form" name="lightBand1" placeholder="" id="lightBand1"/>
<span id="email_result"></span>
</td>
<td class="labelcell">
<input type="button" class="removerow" id="removerow0" name="removerow0" value="Remove">
</td>
</tr>
</div>
</tbody>
<tfoot>
<tr>
</tr>
<tr>
<button type="button" id="addrow" style="margin-bottom: 1%;">Add Row</button>
</tr>
</tfoot>
</table>
script:
$("#addrow").on('click', function() {
let rowIndex = $('.auto_num').length + 1;
let rowIndexx = $('.auto_num').length + 1;
var newRow = '<tr><td><input class="auto_num" type="text" name="entryCount" value="' + rowIndexx + '" /></td>"' +
'<td><input name="lightBand'+rowIndex+'" id="lightBand1" value="" class="form" type="number" /></td>"' +
' <span id="email_result"></span>' +
'<td><input type="button" class="removerow" id="removerow' + rowIndex + '" name="removerow' + rowIndex + '" value="Remove"/></td>';
$("#applicanttable > tbody > tr:last").after(newRow);
});
ajax:
$(document).ready(function(){
$('#lightBand1').change(function(){
var lightBand1 = $('#lightBand1').val();
if(lightBand1 != '')
{
$.ajax({
url:"<?php echo base_url(); ?>participant/check_number_avalibility",
method:"POST",
data:{lightBand1:lightBand1},
success:function(data){
$('#email_result').html(data);
}
});
}
});
});
Controller:
function check_number_avalibility()
{
if(!filter_var($_POST["lightBand1"], FILTER_VALIDATE_INT))
{
echo '<label class="text-danger"><span class="glyphicon glyphicon-remove"></span> Invalid LightBand</span></label>';
}
else
{
$this->load->model("Participant_repository");
if($this->participants->is_number_available($_POST["lightBand1"]))
{
echo '<label class="text-danger"><span class="glyphicon glyphicon-remove"></span> LightBand is already registered</label>';
}
else
{
echo '<label class="text-success"><span class="glyphicon glyphicon-ok"></span> LightBand Available</label>';
}
}
}
Model:
function is_number_available($lightBand)
{
$this->db->where('lightBand', $lightBand);
$query = $this->db->get("entry");
if($query->num_rows() > 0)
{
return true;
}
else
{
return false;
}
}
**
$("#addrow").on('click', function() {
let rowIndex = $('.auto_num').length + 1;
let rowIndexx = $('.auto_num').length + 1;
var newRow = '<tr><td><input class="auto_num" type="text" name="entryCount" value="' + rowIndexx + '" /></td>"' +
'<td><input name="light' + rowIndex + '" placeholder="duplicate validation here" id="auto" value="" class="form" type="number" /></td>"' +
'<td><input type="button" class="removerow" id="removerow' + rowIndex + '" name="removerow' + rowIndex + '" value="Remove"/></td>';
$("#applicanttable > tbody > tr:last").after(newRow);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table table-bordered" border="1" id="applicanttable">
<thead>
<tr>
</tr>
</thead>
<tbody>
<div class="row">
<tr>
<th>#</th>
<th>Light</th>
<th>Action</th>
</tr>
<tr id="row_0">
<td>
<input id="#" name="#" class="auto_num" type="text" value="1" readonly />
</td>
<td class="labelcell">
<input value="" class="hehe form-control" name="light1" placeholder="duplicate validation here" required id="auto" />
</td>
<td class="labelcell">
<input type="button" class="removerow" id="removerow0" name="removerow0" value="Remove">
</td>
</tr>
</div>
</tbody>
<tfoot>
<tr>
</tr>
<tr>
<button type="button" id="addrow" style="margin-bottom: 1%;">Add Row</button>
</tr>
</tfoot>
</table>
**
As your input are dynamically generated you need bind it with static element so change your event handler like this $(document).on('change', 'input[name*=lightBand]', function() {..}) .Then , use $(this).val() to get value of input where change has occurred and pass same to your ajax .
In your current jquery code you have many duplicate ids so change them to class . Also , add class email_result to your span tag currrently you have id here and <span class="email_result"></span> is outside td tag put that inside td tag .
Updated jquery code:
$(document).on('change', 'input[name*=lightBand]', function() {
var lightBand1 = $(this).val(); //get value
var selector = $(this)//save slector
if (lightBand1 != '') {
$.ajax({
url: "<?php echo base_url(); ?>participant/check_number_avalibility",
method: "POST",
data: {
lightBand1: lightBand1
},
success: function(data) {
selector.next('.email_result').html(data);//use next here ..
}
});
}
});
Quick Demo :
$("#addrow").on('click', function() {
let rowIndex = $('.auto_num').length + 1;
let rowIndexx = $('.auto_num').length + 1;
var newRow = '<tr><td><input class="auto_num" type="text" name="entryCount" value="' + rowIndexx + '" /></td>"' +
'<td><input name="lightBand' + rowIndex + '" value="" class="form" type="number" /> <span class="email_result"></span></td>"' +
'<td><input type="button" class="removerow" id="removerow' + rowIndex + '" name="removerow' + rowIndex + '" value="Remove"/></td>';
$("#applicanttable > tbody > tr:last").after(newRow);
});
$(document).on('change', 'input[name*=lightBand]', function() {
var lightBand1 = $(this).val(); //get value
var selector = $(this) //save slector
selector.next('.email_result').html("") //empty previous error
if (lightBand1 != '') {
/*$.ajax({
url: "<?php echo base_url(); ?>participant/check_number_avalibility",
method: "POST",
data: {
lightBand1: lightBand1
},
success: function(data) {*/
selector.next('.email_result').html("NOT GOOD"); //use next here ..
/* }
});*/
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<table class="table table-bordered" border="1" id="applicanttable">
<thead>
<tr>
</tr>
</thead>
<tbody>
<div class="row">
<tr>
<th>#</th>
<th>Light</th>
<th>Action</th>
</tr>
<tr id="row_0">
<td>
<input id="#" name="#" class="auto_num" type="text" value="1" readonly />
</td>
<td class="labelcell">
<input value="" class="form" name="lightBand1" placeholder="" id="lightBand1" />
<span class="email_result"></span>
</td>
<td class="labelcell">
<input type="button" class="removerow" id="removerow0" name="removerow0" value="Remove">
</td>
</tr>
</div>
</tbody>
<tfoot>
<tr>
</tr>
<tr>
<button type="button" id="addrow" style="margin-bottom: 1%;">Add Row</button>
</tr>
</tfoot>
</table>
I am updating my cart quantity using ajax. After successfully updating of the cart, when I load the cart and body of the current page the toggle menu of the my cart button does not work the first time. But when I update second time after loading the cart and body the toggle menu works.
My current code:
'remove': function(product_id, flag) {
// alert(product_id);
// alert(flag);
$.ajax({
url: 'includes/addToCart.php',
type: 'post',
data: 'product_id=' + product_id + '&flag='+flag,
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
// Need to set timeout otherwise it wont update the total
setTimeout(function () {
$('#cart > button').html('<span class="lg">My Cart</span><span><i class="fa fa-shopping-basket"></i> ('+json['total']+') items</span>');
}, 100);
setTimeout(function () {
// if(json['key'] == "blank")
$('#cart > ul').load('includes/loadcart.php');
}, 100);
setTimeout(function () {
$('body').load('cart.php');
}, 100);
},
});
In the console I am getting this error when it executes:
Synchronous XMLHttpRequest on the main thread is deprecated because of
its detrimental effects to the end user’s experience.
I have used the async: true, and async: false
same problem persists
here is my html code where the value displayed
<div class="btn-group btn-block" id="cart">
<button class="btn btn-viewcart dropdown-toggle" data-loading-text="Loading..." data-toggle="dropdown" type="button" aria-expanded="false" id="cart_total"><span class="lg">My Cart</span><span><i class="fa fa-shopping-basket"></i> (<?=$_SESSION['totalitem']?>) items</span></button>
<ul class="dropdown-menu pull-right" ><li>
<table id="cart_item" class="table table-striped">
<tbody>
<?php
if(empty($_SESSION['cart'])){
?>
<tr>
<td align="center" style="font-weight: bold; font-size: 14px;" colspan="5">Your Cart Is empty</td>
</tr>
<?php
}
else{
$subtotal = 0;
foreach($_SESSION['cart'] as $key=>$value){
$subtotal = $subtotal + ($_SESSION['cart'][$key]['price']*$_SESSION['cart'][$key]['qty']);
?>
<tr>
<td class="text-center"> <img class="img-thumbnail" title="iPhone" alt="iPhone" src="../photo/<?=$_SESSION['cart'][$key]['img']?>" width="57px" height="57px">
</td>
<td class="text-left"><?=$_SESSION['cart'][$key]['name']?>
</td>
<td class="text-right">x <?=$_SESSION['cart'][$key]['qty']?></td>
<td class="text-right">$<?=$_SESSION['cart'][$key]['price']*$_SESSION['cart'][$key]['qty']?></td>
<td class="text-center"><button class="btn btn-danger btn-xs" title="Remove" onclick="cart.remove('<?=$_SESSION['cart'][$key]['id']?>','delete');" type="button"><i class="fa fa-times"></i></button></td>
</tr>
<?php
}
}
$vat= $subtotal * (20/100);
$total = $subtotal + $vat;
?>
</tbody></table>
</li><li>
<?php
if(!empty($_SESSION['cart']))
{
?>
<div>
<table class="table table-bordered">
<tbody><tr>
<td class="text-right"><strong>Sub-Total</strong></td>
<td class="text-right">$<?=$subtotal?></td>
</tr>
<tr>
<td class="text-right"><strong>Eco Tax (-2.00)</strong></td>
<td class="text-right">$2.00</td>
</tr>
<tr>
<td class="text-right"><strong>VAT (20%)</strong></td>
<td class="text-right">$<?=$vat?></td>
</tr>
<tr>
<td class="text-right"><strong>Total</strong></td>
<td class="text-right">$<?=$total?></td>
</tr>
</tbody></table>
<p class="text-right"><strong><i class="fa fa-shopping-cart"></i> View Cart</strong> <strong><i class="fa fa-share"></i> Checkout</strong></p>
</div>
<?php
}
?>
</li></ul>
</div>
i have error when i update row to database.
my problem is not update the row and call me when i upload pic with update the file upload not define in index.
my controller :
public function addedit(){
$events = new events_model();
$prodID = $this->input->post('hID');
$text = $this->input->post('ev_text');
$pic = $this->do_upload('ev_pic');
$submit = $this->input->post('submit');
if($submit){
if(!empty($prodID)){
$this->data['events'] = $events->UpdatePost($prodID, $text , $pic );
$this->data['pagetitle'] = "Show Info";
$this->data['success']= "Update Done";
}else{
$this->data['success'] = "Add Done";
}
$this->data['status'] = "1";
}else{
$this->data['status'] = "0";
$this->data['errors'] = "Error";
}
$this->template->build('admin/events/add',$this->data);
}
and model :
function UpdatePost($prodID, $text , $pic ) {
if ($pic == ""){
$vales = array('ev_id' => $prodID , 'ev_text' => $text);
}else{
$vales = array('ev_id' => $prodID , 'ev_text' => $text , 'ev_pic' => $pic);
}
$query = $this->db->update($this->table_name, $vales) or die (mysql_error());
$result = array();
$result["process"] = "ok";
echo "1";
}
and view :
<div class="widget-body">
<table class="data-table" action="./administrator/categories/delete/"><!-- Table Conversion: See Section E in custom.js -->
<thead>
<tr>
<th class="sorting no-background" rowspan="1" colspan="1" style="width: 35px;"><input type="checkbox" id="checkall" /></th>
<th class="sorting" rowspan="1" colspan="1" style="width: 343px;">Tittle</th>
<th class="sorting" rowspan="1" colspan="1" style="width: 100px;">Date</th>
<th class="sorting no-background" rowspan="1" colspan="1" style="width: 70px;">#</th>
</tr>
</thead>
<tbody>
<?php $ctr = 0; ?>
<?php foreach ($events as $n): ?>
<tr>
<td><input class="checkrow" type="checkbox" value="<?php echo $n->ev_id; ?>" /></td>
<td class=" sorting_1"><?= $n->ev_text; ?></td>
<td class="center"><?= $n->ev_date; ?></td>
<td>
<span>Edit</span>
<span>Del</span>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<div id="table-extra">
<div id="table-action">
<input action="./administrator/<?php echo $this->uri->segment(2)."/deleteitems" ?>" class="btn-theme table-button btn-hover-black DeleteItems" id="submit" type="button" value="Delete" />
</div>
<div class="paginate">
<ul>
<?= $this->pagination->create_links(); ?>
</ul>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
where problem in my code , and i wont to update success.
you don't load models like this $events = new events_model(); in CI, you should do it like this :
$this->load->model('Model_name');
$this->Model_name->function();
ref : http://ellislab.com/codeigniter/user-guide/general/models.html#loading