Jump to content

Moorcam

Members
  • Posts

    197
  • Joined

  • Last visited

Everything posted by Moorcam

  1. Already asked for it here
  2. Hi mate, Sorry. Made a few changes but the above was the culprit really. Here is the full update. Controller: public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['tour'] = $this->Model_dashboard->all_tour('p_id'); $data['total_category'] = $this->Model_dashboard->show_total_category(); $data['total_news'] = $this->Model_dashboard->show_total_news(); $data['total_motel'] = $this->Model_dashboard->show_total_motel(); $data['total_tour'] = $this->Model_dashboard->show_total_tour(); $data['total_team_member'] = $this->Model_dashboard->show_total_team_member(); $data['total_agent'] = $this->Model_dashboard->show_total_agent(); $data['total_service'] = $this->Model_dashboard->show_total_service(); $data['total_testimonial'] = $this->Model_dashboard->show_total_testimonial(); $data['total_traveller'] = $this->Model_dashboard->show_total_traveller(); $data['amount_paid'] = $this->Model_dashboard->show_amount_paid(); $data['total_fleet'] = $this->Model_dashboard->show_total_fleet(); $data['total_driver'] = $this->Model_dashboard->show_total_driver(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_dashboard',$data); $this->load->view('admin/view_footer'); } Model: public function all_tour() { $e_id = $this->session->userdata('e_id'); $query = $this->db->query("SELECT * FROM tbl_tour WHERE e_id = $e_id ORDER BY p_id ASC"); return $query->result_array(); } View: <table class="table table-striped"> <tr> <th>Tour</th> <th>Departure Date</th> <th>Return Date</th> <th>Fleet Number</th> </tr> <?php foreach($tour as $row):?> <tr> <td><?php echo $row['p_name']; ?></td> <td><?php echo $row['p_start_date']; ?></td> <td><?php echo $row['p_end_date']; ?></td> <td><?php echo $row['v_number']; ?></td> </tr> <?php endforeach;?> </table>
  3. Fixed Change the following: <td><?php echo $job->start_date;?></td> <td><?php echo $job->name;?></td> To... <td><?php echo $row['p_start_date']; ?></td> <td><?php echo $row['p_name']; ?></td>
  4. Ok, I have added the following to the Controller index and now getting no error. But, not getting anything at all lol. $data['tour'] = $this->Model_dashboard->tour('p_id');
  5. So, when a user logs in, I would like to grab data from the db and display it based on their id, which is in a session. Here is my Controller: public function jobs() { if($this->session->userdata('e_id')){ $id = $this->session->userdata('e_id'); $data['tour'] = $this->usermodel->job($id); $this->load->view('tour',$data); }else{ echo "No results"; } } Here is my Model: public function job($id) { $this->db->select('*') ->from('tbl_tour') ->where('e_id', $id); return $this->db->get()->result(); } And finally, View: <table class="table table-striped"> <tr> <th>Date</th> <th>Tour</th> </tr> <?php foreach($tour as $job):?> <tr> <td><?php echo $job->start_date;?></td> <td><?php echo $job->name;?></td> </tr> <?php endforeach;?> </table> When executing I get Undefined variable: tour And also: Message: Invalid argument supplied for foreach() If anyone can help with this it would be appreciated.
  6. Fixed. Was not getting id from database. So, changed function update($id) { $this->db->where('id',$id); $this->db->update('tbl_team_member',$data); } to this function update($data) { $this->db->where('id',$this->session->userdata('id')); $this->db->update('tbl_team_member',$data); } Just in case anyone else runs into same issue.
  7. Hi guys, Been fighting with this and can't get it to work. Basically, on submit, session is being updated but data is not being sent to the database. Here is my view_profile.php <?php if(!$this->session->userdata('id')) { redirect(base_url().'admin'); } ?> <section class="content-header"> <div class="content-header-left"> <h1>Edit Profile</h1> </div> </section> <section class="content" style="min-height:auto;margin-bottom: -30px;"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> </div> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <div class="nav-tabs-custom"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab_1" data-toggle="tab">Update Information</a></li> <li><a href="#tab_2" data-toggle="tab">Update Photo</a></li> <li><a href="#tab_3" data-toggle="tab">Update Password</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab_1"> <?php echo form_open(base_url().'admin/profile/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Display Name <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="name" value="<?php echo $this->session->userdata('name'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Email Address <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="email" value="<?php echo $this->session->userdata('email'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Phone <span>*</span></label> <div class="col-sm-4"> <input type="text" class="form-control" name="phone" value="<?php echo $this->session->userdata('phone'); ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form1">Update Information</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> <div class="tab-pane" id="tab_2"> <?php echo form_open_multipart(base_url().'admin/profile/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Existing Photo</label> <div class="col-sm-6" style="padding-top:6px;"> <?php if($this->session->userdata('photo') ==''): ?> <img src="<?php echo base_url(); ?>public/img/no-photo.jpg" class="existing-photo" alt="profile photo" width="140"> <?php else: ?> <img src="<?php echo base_url(); ?>public/uploads/<?php echo $this->session->userdata('photo'); ?>" class="existing-photo" width="140"> <?php endif; ?> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">New Photo</label> <div class="col-sm-6" style="padding-top:6px;"> <input type="file" name="photo"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form2">Update Photo</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> <div class="tab-pane" id="tab_3"> <?php echo form_open(base_url().'admin/profile/update',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Password </label> <div class="col-sm-4"> <input type="password" class="form-control" name="password"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Retype Password </label> <div class="col-sm-4"> <input type="password" class="form-control" name="re_password"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form3">Update Password</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> </div> </div> </div> </div> </section> Here is my controller - Profile.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Profile extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('admin/Model_common'); $this->load->model('admin/Model_profile'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_profile',$data); $this->load->view('admin/view_footer'); } public function update() { $error = ''; $success = ''; $data['setting'] = $this->Model_common->get_setting_data(); if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email'); if($this->form_validation->run() == FALSE) { $valid = 0; $error = validation_errors(); } if($valid == 1) { $form_data = array( 'email' => $_POST['email'], 'name' => $_POST['name'], 'phone' => $_POST['phone'] ); $this->Model_profile->update($form_data); $success = 'Profile Information is updated successfully!'; $this->session->set_userdata($form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } if(isset($_POST['form2'])) { $valid = 1; $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $data['error'] = 'You must have to upload jpg, jpeg, gif or png file<br>'; } } else { $valid = 0; $data['error'] = 'You must have to select a photo<br>'; } if($valid == 1) { // removing the existing photo unlink('./public/uploads/'.$this->session->userdata('photo')); // updating the data $final_name = 'user-'.'.'.$ext; move_uploaded_file( $path_tmp, './public/uploads/'.$final_name ); $form_data = array( 'photo' => $final_name ); $this->Model_profile->update($id,$form_data); $success = 'Photo is updated successfully!'; $this->session->set_userdata($id,$form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } if(isset($_POST['form3'])) { $valid = 1; $this->form_validation->set_rules('password', 'Password', 'trim|required'); $this->form_validation->set_rules('re_password', 'Retype Password', 'trim|required|matches[password]'); if($this->form_validation->run() == FALSE) { $valid = 0; $error = validation_errors(); } if($valid == 1) { $form_data = array( 'password' => md5($_POST['password']) ); $this->Model_profile->update($id,$form_data); $success = 'Password is updated successfully!'; $this->session->set_userdata($id,$form_data); $this->session->set_flashdata('success',$success); redirect(base_url().'admin/profile'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/profile'); } } $data['setting'] = $this->Model_common->get_setting_data(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_profile',$id,$data); $this->load->view('admin/view_footer'); } } And finally, my Model_profile.php (only need to update) No errors etc. Any help would be appreciated. Cheers, Dan <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_profile extends CI_Model { function update($id) { $this->db->where('id',$id); $this->db->update('tbl_team_member',$data); } }
  8. Just adding to this. I also wanted this to calculate tax and format with the correct locale, tax name (example: GST for Australia). So, after hours of clowning around, pulling hair out, Googling, and channelling the masters of Code who have long passed away, I finally have it doing what I want. For those of you in the same creek without a paddle, I will share my newfound expertise with you: <?php if($setting['site_currency'] == 'EUR') { $locale = 'en-IE'; } if($setting['site_currency'] == 'GBP') { $locale = 'en-GB'; } if($setting['site_currency'] == 'USD') { $locale = 'en-US'; } if($setting['site_currency'] == 'AUD') { $locale = 'en-AU'; } ?> <script> $(document).ready(function() { $('#numberPerson').on('change',function() { var format = (num) => new Intl.NumberFormat('<?php echo $locale; ?>', { style: 'currency', currency: '<?php echo $setting['site_currency']; ?>' }).format(num); var selectVal = $('#numberPerson').val(); var selectPrice = <?php echo $p_price['p_price_single']; ?>; var taxRate = <?php echo $setting['tax_amount']; ?>; var salesTax = selectPrice * taxRate / 100; var total = selectPrice + salesTax; var totalPrice = selectVal * total; $('#totalPrice').text(format(totalPrice)); }); }); </script> It's probably not what the true experts would do but it works and does what I want it to do and that's what matters. Love you Bye
  9. Scrap my last reply. I am tired and read it wrong. Been driving Interstate last few days. Did it again, looked at it, went, nope, then looked again, did it, and yep. You are a legend. Thank you.
  10. Tried that man. Still no change. Total stays the same.
  11. Hi there, Thanks for the reply. No, only the ID and quantity is being sent forward. I have tried a few different suggestions I have found on Google with this but nothing working. I guess it's not a major issue with "$3000" being displayed rather than "$3,000.00" but I am stubborn lol
  12. Hi guys, I feel this is a Javascript issue so here goes. I am trying to update the total cost of a ticket by selecting the number of passengers from a dropdown. It works. However, not when I format the output within the js by using a number_format() function. Here is the Form: <div class="row book-now"> <div class="col-md-12"> <?php echo form_open(base_url().'payment',array('class' => '')); ?> <input type="hidden" name="p_id" value="<?php echo $id; ?>"> <input type="hidden" name="p_price_single" value="<?php echo number_format($tour['p_price_single'],2); ?>"> <div class="row"> <div class="col-md-12 col-sm-12"> <div class="form-group"> <label>Total Price (per person)</label> <div class="mb_5" style="font-size:32px;"> <?php echo $symbol; ?><?php echo number_format($tour['p_price_single'],2); ?> </div> <div class="sep mb_10"></div> <label>Number of Persons</label> <select id="numberPerson" name="number_of_person" class="custom-select select2 mb_15" style="width: auto;"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> </select> <div class="sep mb_15"></div> <label>Total Price</label> <div class="mb_15" style="font-size:32px;"> <?php echo $symbol; ?><span id="totalPrice"><?php echo number_format($tour['p_price_single'], 2); ?></span> </div> </div> </div> </div> Here is the JS without the function: <script> $(document).ready(function() { $('#numberPerson').on('change',function() { var selectVal = $('#numberPerson').val(); var selectPrice = <?php echo $p_price['p_price_single']; ?>; var totalPrice = selectVal * selectPrice; $('#totalPrice').text(totalPrice); }); }); </script> The above works. However, when the total is calculated from the selection in the dropdown, the total amount loses format. So, for example, if 2 is selected it will show $3000 instead of $3,000.00 Here is the Javascript WITH the number_format function: <script> $(document).ready(function() { $('#numberPerson').on('change',function() { var selectVal = $('#numberPerson').val(); var selectPrice = <?php echo number_format($p_price['p_price_single'], 2); ?>; var totalPrice = selectVal * selectPrice; $('#totalPrice').text(totalPrice); }); }); </script> This just doesn't allow any calculation. The total will stay formatted but just not calculate. Any help would be greatly appreciated. Cheers, Dan
  13. Ignore my impatient and lazy outburst of the "Please rescue me!". I went and put my grown up pants on and figured it out. I was missing some of the Model_FFleet file. Jeesh!
  14. Hi guys, I am using this same code on other sections of the application with no issues but on this particular one I am getting "Undefined Method "Model_fleet::show()" Here is Fleet.php line 16 is the error: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Fleet extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('admin/Model_common'); $this->load->model('admin/Model_fleet'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['fleet'] = $this->Model_fleet->show(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_fleet',$data); $this->load->view('admin/view_footer'); } public function add() { $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('v_number', 'Fleet Number', 'trim|required'); $this->form_validation->set_rules('designation', 'Designated Driver', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $error .= 'You must have to upload jpg, jpeg, gif or png file for featured photo<br>'; } } else { $valid = 0; $error .= 'You must have to select a photo for featured photo<br>'; } if($valid == 1) { $next_id = $this->Model_fleet->get_auto_increment_id(); foreach ($next_id as $row) { $ai_id = $row['Auto_increment']; } $final_name = 'fleet-'.$ai_id.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name; $new_width = 600; $new_height = 600; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $final_name_thumb = 'fleet-'.$ai_id.'-thumb'.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name_thumb; $new_width = 260; $new_height = 260; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'], 'photo' => $final_name ); $this->Model_fleet->add($form_data); $success = 'Fleet is added successfully!'; $this->session->set_flashdata('success',$success); redirect(base_url().'admin/fleet'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/fleet/add'); } } else { $this->load->view('admin/view_header',$data); $this->load->view('admin/view_fleet_add',$data); $this->load->view('admin/view_footer'); } } public function edit($id) { $tot = $this->Model_fleet->fleet_check($id); if(!$tot) { redirect(base_url().'admin/fleet'); exit; } $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('v_number', 'Fleet Number', 'trim|required'); $this->form_validation->set_rules('designation', 'Designation', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } $path = $_FILES['photo']['name']; $path_tmp = $_FILES['photo']['tmp_name']; if($path!='') { $ext = pathinfo( $path, PATHINFO_EXTENSION ); $file_name = basename( $path, '.' . $ext ); $ext_check = $this->Model_common->extension_check_photo($ext); if($ext_check == FALSE) { $valid = 0; $error .= 'You must have to upload jpg, jpeg, gif or png file for featured photo<br>'; } } if($valid == 1) { $data['fleet'] = $this->Model_fleet->get_fleet($id); if($path == '') { $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'] ); $this->Model_fleet->update($id,$form_data); } if($path != '') { unlink('./public/uploads/'.$_POST['current_photo']); $final_name = 'fleet-'.$id.'.'.$ext; $temp_arr = explode('.',$_POST['current_photo']); $temp_final = $temp_arr[0].'-thumb'.'.'.$temp_arr[1]; unlink('./public/uploads/'.$temp_final); $final_name = 'fleet-'.$id.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name; $new_width = 600; $new_height = 600; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $final_name_thumb = 'fleet-'.$id.'-thumb'.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name_thumb; $new_width = 260; $new_height = 260; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'], 'photo' => $final_name ); $this->Model_fleet->update($id,$form_data); } if($path != '') { unlink('./public/uploads/'.$_POST['current_photo']); $final_name = 'fleet-'.$id.'.'.$ext; $temp_arr = explode('.',$_POST['current_photo']); $temp_final = $temp_arr[0].'-thumb'.'.'.$temp_arr[1]; unlink('./public/uploads/'.$temp_final); $final_name = 'fleet-'.$id.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name; $new_width = 600; $new_height = 600; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $final_name_thumb = 'fleet-'.$id.'-thumb'.'.'.$ext; $source_image = $path_tmp; $destination = './public/uploads/'.$final_name_thumb; $new_width = 260; $new_height = 260; $quality = 100; $this->Model_common->image_handler($source_image,$destination,$new_width,$new_height,$quality); $form_data = array( 'v_number' => $_POST['v_number'], 'designation' => $_POST['designation'], 'v_reg' => $_POST['v_reg'], 'v_pax' => $_POST['v_pax'], 'photo' => $final_name ); $this->Model_fleet->update($id,$form_data); } $success = 'Fleet is updated successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'admin/fleet'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'admin/fleet/edit/'.$id); } } else { $data['fleet'] = $this->Model_fleet->get_fleet($id); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_fleet_edit',$data); $this->load->view('admin/view_footer'); } } public function delete($id) { // If there is no Fleet in this id, then redirect $tot = $this->Model_fleet->fleet_check($id); if(!$tot) { redirect(base_url().'admin/fleet'); exit; } $data['fleet'] = $this->Model_fleet->get_fleet($id); if($data['fleet']) { unlink('./public/uploads/'.$data['fleet']['photo']); $temp_arr = explode('.',$data['fleet']['photo']); $temp_final = $temp_arr[0].'-thumb'.'.'.$temp_arr[1]; unlink('./public/uploads/'.$temp_final); } $this->Model_fleet->delete($id); $success = 'Fleet is deleted successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'admin/fleet'); } } Here is Model_fleet.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_fleet extends CI_Model { function get_auto_increment_id() { $sql = "SHOW TABLE STATUS LIKE 'tbl_fleet'"; $query = $this->db->query($sql); return $query->result_array(); } function get_fleet_number_by_id($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function show() { $sql = "SELECT * FROM tbl_fleet"; $query = $this->db->query($sql); return $query->result_array(); } function add($data) { $this->db->insert('tbl_fleet',$data); return $this->db->insert_id(); } function update($id,$data) { $this->db->where('v_id',$id); $this->db->update('tbl_fleet',$data); } function delete($id) { $this->db->where('v_id',$id); $this->db->delete('tbl_fleet'); } function getData($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function fleet_check($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function get_fleet($id) { $sql = 'SELECT * FROM tbl_fleet WHERE v_id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } } And finally view_fleet.php <?php if(!$this->session->userdata('id')) { redirect(base_url().'admin'); } ?> <section class="content-header"> <div class="content-header-left"> <h1>View Fleets</h1> </div> <div class="content-header-right"> <a href="<?php echo base_url(); ?>admin/fleet/add" class="btn btn-primary btn-sm">Add New Fleet</a> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> <div class="box box-info"> <div class="box-body table-responsive"> <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>ID</th> <th>Photo</th> <th>Designation</th> <th>Fleet #</th> <th>Registration</th> <th>Max Pax <th width="140">Action</th> </tr> </thead> <tbody> <?php $i=0; foreach ($fleet as $row) { $i++; ?> <tr> <td><?php echo $i; ?></td> <td style="width:130px;"><img src="<?php echo base_url(); ?>public/uploads/<?php echo $row['photo']; ?>" alt="<?php echo $row['v_number']; ?>" style="width:120px;"></td> <td><?php echo $row['designation']; ?></td> <td><?php echo $row['v_number']; ?></td> <td><?php echo $row['v_reg']; ?></td> <td><?php echo $row['v_pax']; ?></td> <td> <a href="<?php echo base_url(); ?>admin/fleet/edit/<?php echo $row['v_id']; ?>" class="btn btn-primary btn-xs">Edit</a> <a href="<?php echo base_url(); ?>admin/fleet/delete/<?php echo $row['v_id']; ?>" class="btn btn-danger btn-xs" onClick="return confirm('Are you sure?');">Delete</a> </td> </tr> <?php } ?> </tbody> </table> </div> </div> </div> </div> </section> I can't work out why this is happening as all other sections, use the same code concept and layout with no issue. Any guidance would be appreciated. Cheers Dan
  15. By using <button onclick="myFunction('<?php echo $target;?>')">go to url</button> And from looking at the code: $target="target"; You are asking the myfunction to look for 'target' That's all it will look for is 'target'. Change it to $target=$row['target']; I could be wrong though. But that's how I am seeing it.
  16. Thank you so much mate. That resolved it.
  17. Howdy folks, Been a while. Hope all is well. Anyway, I have run into a pickle and can't for the life of me get out of it. I am trying to calculate the total amount of money in a database table. Table is called tbl_payment. The information is displayed in the admin dashboard. Here is the section from view_Dashboard file: <div class="col-md-4 col-sm-6 col-xs-12"> <div class="info-box"> <span class="info-box-icon bg-green"><i class="fa fa-map-signs"></i></span> <div class="info-box-content"> <span class="info-box-text">Total Income</span> <span class="info-box-number"><?php echo $paid_amount; ?></span> </div> </div> </div> Here is the Controller file - Dashboard.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Dashboard extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('admin/Model_common'); $this->load->model('admin/Model_dashboard'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['total_category'] = $this->Model_dashboard->show_total_category(); $data['total_news'] = $this->Model_dashboard->show_total_news(); $data['total_destination'] = $this->Model_dashboard->show_total_destination(); $data['total_tour'] = $this->Model_dashboard->show_total_tour(); $data['total_team_member'] = $this->Model_dashboard->show_total_team_member(); $data['total_client'] = $this->Model_dashboard->show_total_client(); $data['total_service'] = $this->Model_dashboard->show_total_service(); $data['total_testimonial'] = $this->Model_dashboard->show_total_testimonial(); $data['total_traveller'] = $this->Model_dashboard->show_total_traveller(); $data['total_vehicle'] = $this->Model_dashboard->show_total_vehicle(); $data['paid_amount'] = $this->Model_dashboard->show_total_paid_amount(); $this->load->view('admin/view_header',$data); $this->load->view('admin/view_dashboard',$data); $this->load->view('admin/view_footer'); } } And finally, the Model file - Model_dashboard.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_dashboard extends CI_Model { public function show_total_category() { $sql = 'SELECT * from tbl_category'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_news() { $sql = 'SELECT * FROM tbl_news'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_destination() { $sql = 'SELECT * from tbl_destination'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_tour() { $sql = 'SELECT * from tbl_tour'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_team_member() { $sql = 'SELECT * from tbl_team_member'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_client() { $sql = 'SELECT * from tbl_client'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_service() { $sql = 'SELECT * from tbl_service'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_testimonial() { $sql = 'SELECT * from tbl_testimonial'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_traveller() { $sql = 'SELECT * from tbl_traveller'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_vehicle() { $sql = 'SELECT * from tbl_vehicle'; $query = $this->db->query($sql); return $query->num_rows(); } public function show_total_paid_amount() { $sql = 'SELECT `p_id`, SUM(`paid_amount`) AS `total_paid_amount` FROM `tbl_payment` GROUP BY `p_id`'; $query = $this->db->query($sql); return $query->num_rows(); } } I have tried all I can find. I have 1 record in the Database that shows an amount of $360.00. However, the result in Dashboard is just displaying the number 1. Hope you guys can help. Cheers, Dan
  18. Been here a while and can't remember posting anything in here so thought I had better. Anyways, I am Dan. 50 years old. Anyone who says that life begins at 40 and 50 is the new 21 has no idea. I am Irish. Grew up in a lovely market town in the South East called Dungarvan. Loved it there. I now live in Central Victoria, Australia and have done for almost 14 years. I guess my coding and dev days started many centuries ago. My first taste of any type of development was in school on an old Apple computer where the class created a messaging type thing that only sent messages from one computer to the other. It was absolute shite but at 14 years of age we thought it was amazing. From there I took an interest in website design and hosting and ran a successful VPS Hosting service in Ireland for a number of years while designing websites on the side for clients. I sold that business in 2005 and drank more Guinness than the Brewery could brew and gave up on the whole shebang until about 2+ years ago. Wow, how the coding standards have changed. I am now back to Square One, learning about PHP, JavaScript and this PDO and Bootstrap carry on. 🤔 At the moment I drive Interstate on a regular basis, mostly in Road Coaches and Semi Trucks on an odd occasion. Love it, but want to settle at home. So, myself and an ex- employer of mine are currently working on an application that we hope will allow me to do just that as there is a huge opening in the Market for an app like it here in Australia. Enough said Anyways, pleasure to make your acquaintance.
  19. Is it worth the price though? What does it offer that say, Sublime Text or Visual Studio Code doesn't? Asking for a friend I used Notepad++ for years and recently started to use Sublime Text.
  20. Thought I would add to the list. Been using VentraIP Australia with years. Also used to work for them and still great friends with the owners. Top quality services. http://www.ventraip.com.au
  21. Howdy, Just started to use PDO and loving it so far. Much better than MySQLi. Anyway, would like to know the best reference books available for PHP. If you use reference books, what do you use? Had a google today and found one "The Complete Reference to PHP". Sounded promising but was published in 2007 so not sure if it would be a good buy. Thoughts?
  22. Moorcam

    Video script

    As requinix said, you will need to learn about the workings of CSS and HTML and how they both work together. My advice is to make use of the website w3schools.com and learn these two vital languages. For this to do what you want, wouldn't be surprised if you needed some Javascript too. Post up your HTML with the video in a simple iFrame and playable. Maybe someone here can point you in the right direction.
  23. Not sure if this is what you were looking for but it's what I used when I used MySQLi to upload an image: $image = mysqli_real_escape_string($con, $_FILES['image']['name']); // image file directory $target = "images/".basename($image); if(!empty($_FILES['image']['name'])) { $sql = "UPDATE table SET image='".$image."'"; } $result = mysqli_query($con, $sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } if(!$result){ die('Error: ' . mysqli_error($con)); } else{ $message = ' - <i class="fa fa-check text-success"> Record Updated!</i>'; } } } I know it's not an INSERT but the image upload script should still work. Sorry if this is not what you are looking for. BTW: go to PDO. It's more fun.
  24. Thank you so much man. Really appreciate it. Promise I won't bother you anymore ... until the next issue
  25. Thanks heaps. Now, if there is a scenario where the form needs to be updated but without uploading a new image, at this time it just gets rid of the current image. I need to work out how to prevent that. Previously, before moving to PDO, I had a second insert query inside an if clause. Tried it with this but got an UNEXPECTED else.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.