-
Posts
254 -
Joined
-
Last visited
Everything posted by Moorcam
-
Hi again, I bet you guys have missed me. I am trying to join two tables using LEFT JOIN to get the first name of a driver. This is kinda related to my previous topic about bootstrap modals. I am using the following to join the tables: <?php $sql = "SELECT chtr.id, chtr.charter_name, chtr.fleet_number, chtr.driver, chtr.customer_name, chtr.customer_number, chtr.dep_date, chtr.status, usr.id, usr.fname FROM charters AS chtr LEFT JOIN users AS usr ON chtr.id = usr.id "; if($result = mysqli_query($conn, $sql)){ if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_array($result)){ ?> However, it shows all data in the table except for chtr.id bar one, which does show. I need a Guinness but I am not allowed anymore Any help would be appreciated.
-
Opening one Bootstrap Modal from another Not Working
Moorcam replied to Moorcam's topic in PHP Coding Help
Ok, that created a new issue. It opens the modal but only for one of the entries. <button class="btn btn-primary" data-bs-target="#viewCharter<?php echo $row['id']; ?>" data-bs-toggle="modal">View</button> <div tabindex="-1" class="modal fade" id="viewCharter<?php echo $row['id']; ?>" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"><h4><i class="fa fa-map-marker fa-fw"></i><?php echo $row['charter_name']; ?></h4></div> <div class="modal-body"> <h3><?php echo $row['charter_name']; ?></h3> <p>Leaving at <?php echo $row['dep_date']; ?></p> <p>Customer's name is <?php echo $row['customer_name']; ?> and their contact number is <?php echo $row['customer_number']; ?>.</p> <p>The vehicle for this trip is <?php echo $row['fleet_number']; ?></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-bs-dismiss="modal"><i class="fa fa-ban"></i> <?php echo lang('CLOSE'); ?></button> </div> </div> </div> </div> No idea why but yeah. -
Opening one Bootstrap Modal from another Not Working
Moorcam replied to Moorcam's topic in PHP Coding Help
Changing the ID of the modal I want to open from the other modal works. So with that plan we shall go. Thanks mate. Love your work. -
Opening one Bootstrap Modal from another Not Working
Moorcam replied to Moorcam's topic in PHP Coding Help
That could be the issue. I have a table setup on index.php and when I click View it opens that modal no issues. If I open the View All modal and click on View, it's where the thing uses a toilet. I begin to ask myself why I decided to save space by using modals instead of separate files for each section. -
Opening one Bootstrap Modal from another Not Working
Moorcam replied to Moorcam's topic in PHP Coding Help
Doing exactly what they are doing in the example. Yet, their example works. How stupid is that? -
Opening one Bootstrap Modal from another Not Working
Moorcam replied to Moorcam's topic in PHP Coding Help
Sure have. Same result. Closes first one but doesn't open the second one. -
Opening one Bootstrap Modal from another Not Working
Moorcam replied to Moorcam's topic in PHP Coding Help
Yeah gave that a crack. Still same. Closes original one and doesn't open the new one. -
Hi guys, Not sure where this one should be posted but will post here. Please move to appropriate if needed. I am trying to open a new modal by clicking a link inside another one. It doesn't seem to want to play ball and the open modal just closes. Can anyone give me a punch bag or maybe just point me in the right direction? The button: <button type="button" id="viewcharterBtn" data-bs-toggle="modal" data-bs-target="#viewcharterModal<?php echo $row['id']; ?>" data-bs-dismiss="modal" class="btn btn-primary">View</button> The modal I want to open: <div tabindex="-1" class="modal" id="viewcharterModal<?php echo $row['id']; ?>" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"><h4><i class="fa fa-map-marker fa-fw"></i><?php echo $row['charter_name']; ?></h4></div> <div class="modal-body"> <h3><?php echo $row['charter_name']; ?></h3> <p>Leaving at <?php echo $row['dep_date']; ?></p> <p>Customer's name is <?php echo $row['customer_name']; ?> and their contact number is <?php echo $row['customer_number']; ?>.</p> <p>The vehicle for this trip is <?php echo $row['fleet_number']; ?></p> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-bs-dismiss="modal"><i class="fa fa-ban"></i> <?php echo lang('CLOSE'); ?></button> </div> </div> </div> </div> Any help would be appreciated.
-
Hi. Not much into contact forms myself but just did a quick google. 6 years old but might give you ideas: https://github.com/SH1R3F/Contact-Form---PHP-OOP
-
Only SELECT queries have WHERE clauses mate.
-
Insert Automatically? I think you need to learn about php and MySQL etc. Here's a good place to start - https://www.phptutorial.net/php-pdo/php-pdo-insert/
-
What errors are you getting, if any? Also, use the code tags when posting to make it easier to read.
-
Redirect to installer if database is empty - Codeigniter 3
Moorcam replied to Moorcam's topic in Frameworks
Thank you -
Hi guys, If my application is not installed, and you go to the main website, it throws the following error: Message: Call to a member function first_row() on bool Now, this is obviously because the database is empty. What I would like to do, instead of showing this error, I would like to automatically redirect to the install directory (if it exists). In Model_common, the following function is what is throwing the error: public function all_setting() { $query = $this->db->query("SELECT * from tbl_settings WHERE id=1 ORDER BY id"); return $query->first_row('array'); } I have tried this but to no avail in Home.php controller under function index if (empty($data['setting'])) { redirect('../install/'); } If anyone could help with this I would appreciate it. Cheers Dan
-
500 Internal error when mod_rewrite enabled
Moorcam replied to Moorcam's topic in Apache HTTP Server
Never mind, Solved. mod_headers was disabled, causing a conflict in .htaccess. -
Hi guys, I have installed WAMP on my local machine. I have copied my project to the /www/ folder and when I open it in the browser, I get a 500 Internal Server Error. If I disable mod_rewrite the error goes away. Anyone got any idea? Nothing in error logs.
-
Hi again all, Posting this for anyone who has experienced similar. It appears Codeigniter 3 has a bug that does not check for file extensions. Thus, not allowing certain files to be uploaded. The workaround is to create a piece of code that will do the checking for us and allow for it to be uploaded. Here is that little piece of code: $ext = strtolower(pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION)); if ($ext != "csv") { // Not a CSV file - send error $this->session->set_flashdata('error', 'Incorrect file extension uploaded. Only .CSV allowed!'); redirect("admin/csv"); } Works a charm, thanks to my good friend Craig.
-
Hi guys, I want to be able to dynamically change a site's color scheme using JS Colorpicker. I have the JS amd form etc all set and the color is updating in the database. However, I need to be able to use that database entry to change a color hex in a xss file. I am using Codeigniter 3 Here is the HTML Form: <div class="tab-pane" id="color"> <?php echo form_open(base_url().'admin/setting/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">Color </label> <div class="col-sm-4"> <input type="text" name="footer_bg" class="form-control jscolor" value="<?php echo $setting['footer_bg']; ?>"> </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="form_color">Update</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> I have the following on the top of the style.php file: <?php header("Content-type: text/css"); ?> This all works fine if I say have the following: <?php header("Content-type: text/css"); $footer_bg = '#333'; ?> background-color: <?php echo $footer_bg; ?>; However, if I try to call the color from settings database table it won't work. Can anyone help with this? Cheers, Dan
-
Hi again folks, This really has me. I have changed to another method of importing, which includes uploading the file to the server and then reading it. Unfortunately, it isn't even uploading. Why? It baffles me as I have other uploads, such as images etc working just fine. Here is the controller now: function importcsv() { $data['fleet'] = $this->Model_fleet->show(); $data['error'] = ''; //initialize image upload error array to empty $config['upload_path'] = './uploads/csv/'; $config['allowed_types'] = 'csv'; $config['max_size'] = '1000'; $this->load->library('upload', $config); // If upload failed, display error if (!$this->upload->do_upload()) { $data['error'] = $this->upload->display_errors(); $this->load->view('admin/fleet', $data); } else { $file_data = $this->upload->data(); $file_path = $file_data['./uploads/csv/']; if ($this->Csvimport->get_array($file_path)) { $csv_array = $this->Csvimport->get_array($file_path); foreach ($csv_array as $row) { $insert_data = array( 'v_number'=>$row['v_number'], 'v_eng_number'=>$row['v_eng_number'], 'v_vin'=>$row['v_vin'], 'v_chassis'=>$row['v_chassis'], 'v_make'=>$row['v_make'], 'v_model'=>$row['v_model'], 'v_height'=>$row['v_height'], 'v_length'=>$row['v_length'], 'v_width'=>$row['v_width'], 'v_reg'=>$row['v_reg'], 'v_pax'=>$row['v_pax'], 'tacho_number'=>$row['tacho_number'], 'service_date'=>$row['service_date'], 'v_notes'=>$row['v_notes'], 'status'=>$row['status'], ); $this->Model_fleet->insert_csv($insert_data); } $this->session->set_flashdata('success', 'Csv Data Imported Succesfully'); redirect(base_url().'csv'); echo "<pre>"; print_r($insert_data); } else $data['error'] = "Error occured"; $this->load->view('admin/fleet', $data); } } Here is the Model: function insert_csv($data) { $this->db->insert('tbl_fleet', $data); } And the form (view): <!-- Modal Start --> <div class="modal fade" id="myModalDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog" style="width:900px;"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel"> Import Fleet </h4> </div> <div class="modal-body"> <div class="form-group"> <h3>Upload Fleet</h3> <h4>From the options below, you can simply import your fleet quickly by uploading a spreadsheet/</h4> <label for="exampleInputFile">Upload Excel or CSV</label> <?php echo form_open_multipart(base_url().'admin/fleet',array('class' => 'form-horizontal')); ?> <input type="file" name="file" ><br><br> <input type="submit" name="submit" value="UPLOAD" class="btn btn-primary"> <?php echo form_close(); ?> </div> </div> </div> </div> </div> <!-- Modal End --> I am also using the csvimport Library as below, which is saved in libraries/Csvimport.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /** * CodeIgniter CSV Import Class * * This library will help import a CSV file into * an associative array. * * This library treats the first row of a CSV file * as a column header row. * * * @package CodeIgniter * @subpackage Libraries * @category Libraries * @author Brad Stinson */ class Csvimport { private $filepath = ""; private $handle = ""; private $column_headers = array(); /** * Function that parses a CSV file and returns results * as an array. * * @access public * @param filepath string Location of the CSV file * @param column_headers array Alternate values that will be used for array keys instead of first line of CSV * @param detect_line_endings boolean When true sets the php INI settings to allow script to detect line endings. Needed for CSV files created on Macs. * @return array */ public function get_array($filepath='', $column_headers='', $detect_line_endings=FALSE) { global $column_headers; // If true, auto detect row endings if($detect_line_endings){ ini_set("auto_detect_line_endings", TRUE); } // If file exists, set filepath if(file_exists($filepath)) { $this->_set_filepath($filepath); } else { return FALSE; } // If column headers provided, set them $this->_set_column_headers($column_headers); // Open the CSV for reading $this->_get_handle(); $row = 0; while (($data = fgetcsv($this->handle, 0, ",")) !== FALSE) { // If first row, parse for column_headers if($row == 0) { // If column_headers already provided, use them if($this->column_headers) { foreach ($this->column_headers as $key => $value) { $column_headers[$key] = trim($value); } } else // Parse first row for column_headers to use { foreach ($data as $key => $value) { $column_headers[$key] = trim($value); } } } else { $new_row = $row - 1; // needed so that the returned array starts at 0 instead of 1 foreach($column_headers as $key => $value) // assumes there are as many columns as their are title columns { $result[$new_row][$value] = trim($data[$key]); } } $row++; } $this->_close_csv(); return $result; } /** * Sets the filepath of a given CSV file * * @access private * @param filepath string Location of the CSV file * @return void */ private function _set_filepath($filepath) { $this->filepath = $filepath; } /** * Sets the alternate column headers that will be used when creating the array * * @access private * @param column_headers array Alternate column_headers that will be used instead of first line of CSV * @return void */ private function _set_column_headers($column_headers='') { if(is_array($column_headers) && !empty($column_headers)) { $this->column_headers = $column_headers; } } /** * Opens the CSV file for parsing * * @access private * @return void */ private function _get_handle() { $this->handle = fopen($this->filepath, "r"); } /** * Closes the CSV file when complete * * @access private * @return array */ private function _close_csv() { fclose($this->handle); } } If anyone can please provide any idea I would love you forever. There are no errors etc, just nothing happening. Cheers, Dan
-
Posted a few posts back, sorry. function saverecords($v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status) { $this->db->insert('tbl_fleet',$v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status); return $this->db->insert_id(); } Anyway, I have tried the following. It shows no result at all. public function import_data(){ if(isset($_POST['file'])) { $csv = $_FILES['file']['tmp_name']; $handle = fopen($csv,"r"); while (($row = fgetcsv($handle, 10000, ",")) != FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } }
-
I have amended that in my last reply. I have tried other methods as well, uploading the file to /uploads/ and trying to read it from there. Can't even get the bloody thing to upload. I give up. Thanks anyway.
-
I am running this just after the success set_flashdata: echo "<pre>"; print_r($this->Model_fleet->saverecords); Nothing
-
Don't think so. I am already updating, adding, deleting data from that same Model. I have also modified the Model code for the saverecords so it is similar to others I am using: function saverecords($v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status) { $this->db->insert('tbl_fleet',$v_number,$v_eng_number,$v_vin,$v_chassis,$v_make,$v_model,$v_height,$v_length,$v_width,$v_reg,$v_pax,$tacho_number,$service_date,$v_notes,$status); return $this->db->insert_id(); } My feeling is it is with the controller part posted below. I am just at a complete loss with it. public function importdata() { $this->load->view('view_fleet'); if(isset($_POST["submit"])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file, "r"); $c = 0;// while(($filesop = fgetcsv($handle, 1000, ",")) !== false) { $v_number = $filesop[0]; $v_eng_number = $filesop[1]; $v_vin = $filesop[2]; $v_chassis = $filesop[3]; $v_make = $filesop[4]; $v_model = $filesop[5]; $v_height = $filesop[6]; $v_length = $filesop[7]; $v_width = $filesop[8]; $v_reg = $filesop[9]; $v_pax = $filesop[10]; $tacho_number = $$filesop[11]; $service_date = $filesop[12]; $v_notes = $filesop[13]; $status = $filesop[14]; if($c<>0){ /* SKIP THE FIRST ROW */ $this->Model_fleet->saverecords( $v_number, $v_eng_number, $v_vin, $$v_chassis, $v_make, $v_model, $v_height, $v_length, $v_width, $v_reg, $v_pax, $tacho_number, $service_date, $v_notes, $status ); } $c = $c + 1; } echo "sucessfully import data !"; }else{ $this->session->set_flashdata('error',$error); redirect(base_url().'admin/fleet/edit/'.$id); } }
-
Same thing. I also sorted the 15 against the 2 variables (missed that) and also still the same.
-
Thank you. That sorted the above error out. Now, no data being imported.