Update status column in codigniter is not working - mysql

Hi guys i am trying to update the status column of my table contentdetails To 0.I don't know what is the exact problem and where i have done mistake i couldn't able to update my status column.
Here is my controller:
function deleteImage() {
// Pass the $id to the contentDelete() method
$id = $this->input->post('image_id');
if ($id) {
$this->Content_model->imageDelete($id);
$this->session->set_flashdata('success', 'Image deleted.');
redirect('Content');
} else {
$this->session->set_flashdata('error', 'Image Id not captured.');
redirect('Content');
}
}
Here is my model:
function imageDelete($id) {
$this->db->set('status', 0); //value that used to update column
$this->db->where('id', $id); //which row want to upgrade
$this->db->update('contentdetails'); //table name
}
Here is my view:
<table class="table table-striped table-bordered" id="dataTable1">
<thead>
<tr>
<th>#</th>
<th>Image path</th>
<th class='text-center'>Delete</th>
</tr>
</thead>
<tbody>
<?php
foreach ($bgimglist as $bgimgs) {
?>
<tr>
<td><?php echo $bgimgs->id; ?></td>
<td><?php echo $bgimgs->details; ?></td>
<td class='text-center'>
<form method="post" action="<?php echo base_url('Content/deleteImage'); ?>">
<input type="text" name="image_id" value="<?php echo $bgimgs->id; ?>">
<button type="submit" onclick="return ConfirmDelete()" class="btn btn-danger btn-xs confirmation" name="login"><i class='fas fa-times'></i></button>
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
Can anyone help me where i have done mistake.
Thanks in advance.

Due to some misunderstanding OP though form_open() also closed the form in code available in the discussion in the above comments. Thus, any further form calls were going to the form that was never closed.
Adding a </form> for the open form solved the issue.

Related

Change button text based on cell value in each table row - Jquery

I have a HTML table that is showing data from DB. A [status] column shows the status of each record as "AVAILABLE" , "BOOKED" or "ON-HOLD". the last column of table is [ACTION] column which contains a BUTTON. If the status of row = "Available" then button text should be "BOOK". Likewise if the status = "BOOKED" or "ON-HOLD" the the button text should be "VIEW". I have applied css successfully via jquery that changes the background-color of status column based on the text in the cell as mentioned above but the same code is not working for button text.
HTML
<tr id="data_row">
<td class="align-middle text-center"><?php echo $Project; ?></td>
<td class="align-middle text-center"><?php echo $Sector; ?></td>
<td class="align-middle text-center"><?php echo $Category ;?></td>
<td class="align-middle text-center"><?php echo $Plot_title ;?></td>
<td class="align-middle text-center"><?php echo $App_date ;?></td>
<td class="align-middle text-center"><?php echo $Customer ;?></td>
<td class="align-middle text-center" id= "status"><?php echo $Status ;?></td>
<td class="align-middle text-center">
<button type="button" name="edit" id="<?php echo $Plot_ID; ?>" class="btn btn-outline-primary btn-sm edit_data" data-toggle="modal" data-target="#modalform" data-backdrop="static" data-keyboard="false">Book</button>
</td>
</tr>
Jquery
$('#myTable tr#data_row td#status').each(function () {
switch ($(this).text()) {
case "Booked":
$(this).css({"background-color":"#eeac88", "color":" #7a3b2e"}); // (WORKING FOR CSS)
$(".edit_data").text("View"); // (NOT WORKING FOR TEXT CHANGE)
break;
case "on-Hold":
$(this).css("background-color","#fefbd8");
$(".edit_data").text("View");
break;
default:
$(this).css({"background-color": "#c5d5c5", "color":"green"});
$(".edit_data").text("Book");
break;
}
});
Try
$(".edit_data").hmtl("View");
Or put a <span> inside the button to access it with .text() method

Why json data is showing in header in codeigniter HMVC - AJAX

I'm new in ajax and I don't know how to get over this error. I don't understand this error. Please help.
Here is my Modal User_m.
I fetch data from database successfully
<?php
class Users_m extends CI_Model
{
public function showAllAdmins()
{
$query = $this->db->get('admin_users');
if($query->num_rows() > 0){
return $query->result();
}else{
return false;
}
}
}
?>
Here is my Controller AdminUsers
I get all data from database through my modal and encode it using by json_encode
but I don't know why this json data is showing on my page header.In this Image
class AdminUsers extends MY_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('AdminUsers/Users_m');
}
public function index()
{
$data['content_view'] = 'AdminUsers/viw_users';
$data['page_title'] = 'Users';
$data['page_descr'] = 'all admin users';
$result = $this->Users_m->showAllAdmins();
echo json_encode($result);
$this->template->admin_template($data);
}
}
And this is my ajax code
When I Every time refresh my page it execute alert Could not get data from database. I don't know How to pass Json data in ajax. I see console log but not show any error. I load jQuery also. Any help will be appreciated. Thanks for your answers.
And when I loop through this it goes to infinity.
$(function(){
showAllAdmins();
function showAllAdmins(){
$.ajax({
type:'ajax',
url: 'http://localhost/hmvcExample/AdminUsers',
async:false,
success: function(data){
var html = '';
var i = 0;
for(i=0; i<data.length; i++){
html +='<tr>'+
'<td>Rakesh</td>'+
'<td>Kumar</td>'+
'<td>Rakeshkrishan1992#gmail.com</td>'+
'<td>Rocky</td>'+
'<td><button class="btn btn-primary">Edit</button> <button class="btn btn-danger">Delete</button></td>'+
'</tr>';
}
$('#showData').html(html);
},
error: function(){
alert('Could not load Data from Database');
}
});
}
});
View file
<div class="box">
<div class="box-header">
<h3 class="box-title">Users List</h3>
<button class="btn btn-success pull-right">Add New</button>
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="example2" class="table table-bordered table-hover table-responsive">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>User Name</th>
<th>Action</th>
</tr>
</thead>
<tbody id="showData">
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
I'm posting a sample code. Please refer.
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>Slno</th>
<th>Name</th>
<th>Username</th>
<th>Email</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="user_table">
<?php if($result) { $i =1; foreach ($result as $row){ ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row->fullname; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php if($row->active == "1"){ ?>
<span class="label label-success"><?php echo 'Active'; ?></span>
<?php }elseif($row->active == "0"){ ?>
<span class="label label-warning"><?php echo 'Inactive'; ?></span>
<?php } ?></td>
<td>
<div class="btn-group">
<a class="btn btn-xs btn-success" href="<?php echo base_url().'admin/user/view_user?id='.$row->user_id.'&action=edit'; ?>" title="View">
<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
</a>
</div>
</td>
</tr>
<?php $i++; } } ?>
</tbody>
</table>
You have to pass the data from the controller as follows
$data['result'] = $result; //your sql query resultset
$this->template->admin_template($data);
No need to use ajax at all. Hope this can help you.
Feel free to ask if you have any queries.

Distinct with join in codeigniter mysql

How can I use Distinct with join in CodeIgniter, I'm trying to fetch customer's name and registered category, but my problem is whiles fetching the data I'm getting data in repetation because of sub-category, I've used distinct but then I'm getting Ambiguous field error, how can I solve this problem.
My View
<table class="table table-hover example1">
<thead>
<tr>
<th>SNo.</th>
<th>Business Name</th>
<th>Category Name</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php $i=0;
foreach($value as $row){ ?>
<tr>
<td><?php echo ++$i;?></td>
<td><?php echo $row->Bussiness_Name;?></td>
<td><?php echo $row->Category_Name;?></td>
<td onClick="RestoreVendor(<?php echo $row->Business_Id; ?>,<?php echo $row->Trash;?>,'<?php echo $row->Bussiness_Name;?>')" class="btn btn-primary">Remove</td>
</tr>
<?php }?>
</tbody>
</table>
My Controller:
public function removecategory()
{
$this->load->model('VendorModel');
$data = $this->VendorModel->remove_category();
$this->load->view('admin/remove_cat', array('value'=>$data));
}
My Model
public function remove_category()
{
$this->db->select('*');
$this->db->distinct('Category_Id');
$this->db->from('business_mapping');
$this->db->join('business_profile_details', 'business_profile_details.Business_Id = business_mapping.Business_Id');
$this->db->join('category_master', 'category_master.Category_Id = business_mapping.Category_Id');
$query = $this->db->get();
return $query->result();
}
result image
You can use below mentioned query.
$query = $this->db->group_by('category_master.Category_Id,business_profile_details.Business_Id');
Please try above, It will help you.
you can use
$this->db->distinct();
Some times distinct not works then you can use
$this->db->group_by('business_mapping.unique_coloumn_Name');

Zend form input box aligning

This is my HTML view:
<tr class="header">
<th>CLASS</th>
<th>NAME</th>
<th>Actions</th>
</tr>
<?php
foreach($this->documents as $row): ?>
<tr>
<td><?php echo $row['CLASS'];?></td>
<td><?php echo $row['NAME'];?></td>
href="/admin/documents/delete?ID=<?php echo $row['ID'];?>">
delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
This is my view Form:
public function init()
{
$CLASS = new Zend_Form_Element_Text('CLASS');
$CLASS->setLabel('CLASS')
->setRequired(true);
$NAME = new Zend_Form_Element_Text('NAME');
$NAME->setLabel('NAME')
->setRequired(true);
$submit = new Zend_Form_Element_Submit('Submit');
$submit->setAttrib('ID', 'submitbutton');
$this->addElements(array($CLASS, $NAME,$submit));
}
I have zend form, having two inputs CLASS and NAME.
How to display CLASS and required input text box column in the same line?
This is my output image:
And same thing, how to put submit and Reset button in the same line?

WordPress - Display Post Content and Post Meta on a Page in the Admin Area

I am trying to create a page in my WordPress Admin Area that displays excerpts of posts and various custom field meta in a table-style layout.
If this were a front-end WordPress Template, I could do this very easily using a WordPress Loop and Query, however, I am not so sure how I would go about doing this on a page in the admin area.
Would it be the same, or would I need to use a completely new method? If so, could someone please provide a working example of how I would do this?
The admin page will be created using an included file within my functions.php - or at least that is the plan at the moment, so I just need help in figuring out how to pull the WordPress Excerpts and Post Meta.
you can use the WP_Query object everytime after WordPress is initialized, so if you like you can even make thousands of nested queries in den WordPress backend if you want to do this.
This is the way to go:
Create an action to add your backend page - write a Plugin or put it into your functions.php
Setup the Menu Page - the code is an example for a full backend administration Page of your Theme
Include your queries using the WP_Query object - optionally make database queries directly (http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query). Possibly use the "widefat" class of WordPress, for pretty formatting.
Make sure that your changes are saved correctly
add_action('admin_menu', 'cis_create_menu');
function cis_create_menu() {
//create new top-level menu
add_menu_page(__('Theme Settings Page',TEXTDOMAIN),__('Configure Theme',TEXTDOMAIN), 'administrator', __FILE__, 'cis_settings_page', '');
//call register settings function
add_action('admin_init','cis_register_settings');
}
function cis_register_settings() {
register_setting('cis-settings-group','cis_options_1','cis_validate_settings');
}
function cis_settings_page() {
// All Text field settings
$op_fields = array(
array(__('Label 1','textdomain'),"Description 1")
);
?>
<div class="wrap">
<h2><?php echo THEME_NAME; _e(": Settings",TEXTDOMAIN); ?></h2>
<?php
settings_errors();
?>
<form method="post" action="options.php">
<?php
settings_fields( 'cis-settings-group' );
$options = get_option('cis_options_1');
?>
<h3><?php _e('General','textdomain'); ?></h3>
<table class="widefat">
<thead>
<tr valign="top">
<th scope="row"><?php _e('Setting','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('Value','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('Description','ultrasimpleshop'); ?></th>
<th scope="row"><?php _e('ID','ultrasimpleshop'); ?></th>
</tr>
</thead>
<tbody>
<?php
// the text-settings we define fast display
$i=1;
foreach($op_fields as $op) {?>
<tr valign="top">
<td><label for="cis_oset_<?php echo $i; ?>"><?php echo $op[0]; ?></label></td>
<td><input size="100" id="cis_oset_<?php echo $i; ?>" name="cis_options_1[cis_oset_<?php echo $i; ?>]" type="text" value="<?php echo esc_attr($options['cis_oset_'.$i]);?>" /></td>
<td class="description"><?php echo $op[1]; ?></td>
<td class="description"><?php echo $i; ?></td>
</tr>
<?php
$i++;
} ?>
</tbody>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes',TEXTDOMAIN) ?>" />
</p>
</form>
</div>
<?php }
// Validate the user input - if nothing to validate, just return
function cis_validate_settings( $input ) {
$valid = array();
$i= 1;
while(isset($input['cis_oset_'.$i])) {
$valid['cis_oset_'.$i] = $input['cis_oset_'.$i];
$i++;
}
$cis_additional_settings = get_option('cis_options_1');
foreach($input as $ikey => $ivalue) {
if($ivalue != $valid[$ikey]) {
add_settings_error(
$ikey, // setting title
"cis_oset_".$ikey, // error ID
str_replace("%s",$ikey,__('Invalid Setting in Settings Area ("%s"). The value was not changed.',TEXTDOMAIN)), // error message
'error' // type of message
);
$valid[$ikey] = $cis_additional_settings[$ikey];
}
}
return $valid;
}
outside the loop you would need to use
$post->post_excerpt
or try this
function get_the_excerpt_here($post_id)
{
global $wpdb;
$query = "SELECT post_excerpt FROM $wpdb->posts WHERE ID = $post_id LIMIT 1";
$result = $wpdb->get_results($query, ARRAY_A);
return $result[0]['post_excerpt'];
}