-
Posts
254 -
Joined
-
Last visited
Everything posted by Moorcam
-
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
-
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.
-
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.
-
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
-
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?
-
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.
-
PHP - How to take an image from an array and save it to MYSQL?
Moorcam replied to Zorglub's topic in PHP Coding Help
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. -
Thank you so much man. Really appreciate it. Promise I won't bother you anymore ... until the next issue
-
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.
-
Had the sandwich and the coffee. No smoke because I gave them up about 2 weeks ago (God help everyone around me) and had a look at the first line. Changed it to the following: if(!empty($_FILES['image']['name'])) { Works perfectly. No idea why that didn't shout at me earlier. Thank you kindly.
-
Hi guys, Using the following code to upload an image to a directory. It aint being funky... if ($_FILES['image']['error'] = UPLOAD_ERR_OK) { // image file directory $target = "images/uploads/".basename($_FILES['image']['name']); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; $post['image'] = $target; }else{ $msg = "Failed to upload image"; $post['image'] = null; } } else { $post['image'] = null; } Can anyone tell me what's up? Thanks guys
-
Ok, I am having a crack here so please be gentle. include_once('includes/header.php'); if(isset($_POST['submit'])){ $id = trim($_SESSION['id']); //$trn_date = trim($db, date("Y-m-d H:i:s")); //$password = $db->real_escape_string(md5($_POST['password'])); $image = trim($_FILES['image']['name']); $name = trim($_POST['name']); $phone = trim($_POST['phone']); $email = trim($_POST['email']); $address = trim($_POST['address']); $license_number = trim($_POST['license_number']); $position = trim($_POST['position']); $role = trim($_POST['role']); $submittedby = trim($_SESSION["username"]); // image file directory $target = "images/".basename($image); if(!empty($_FILES['image']['name'])) { $stmt = $db->prepare("UPDATE users SET name = ?, email = ?, phone = ?, address = ?, license_number = ?, position = ?, role = ?, submittedby = ?, image = ? WHERE id = ?"); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } }else{ $stmt = $db->prepare("UPDATE users SET name = ?, email = ?, phone = ?, address = ?, license_number = ?, position = ?, role = ?, submittedby = ? WHERE id = ?"); } $stmt = $db->execute(array($name, $email, $phone, $address, $license_number, $position, $role, $submittedby, $image)); if($stmt->execute()){ echo 'Done'; }else{ echo 'Not Done'; } } The above gives an error: Fatal error: Uncaught Error: Call to undefined method PDO::execute() That's this line: $stmt = $db->execute(array($name, $email, $phone, $address, $license_number, $position, $role, $submittedby, $image)); I am at a complete roadblock here.
-
Howdy folks, I have decided, after a discussion with Barand, to finally hang up the MySQLi shoes and move over to the dark side of PDO. I am trying to Update a profile, for example, but it is not working. No errors or anything. New to PDO so would love some help on figuring out where I am going wrong. Probably everywhere knowing me lol. Here is the dreaded code: if(isset($_POST['submit'])){ $id = trim($_SESSION['id']); //$trn_date = trim($db, date("Y-m-d H:i:s")); //$password = $db->real_escape_string(md5($_POST['password'])); $image = trim($_FILES['image']['name']); $name = trim($_POST['name']); $phone = trim($_POST['phone']); $email = trim($_POST['email']); $address = trim($_POST['address']); $license_number = trim($_POST['license_number']); $position = trim($_POST['position']); $role = trim($_POST['role']); $submittedby = trim($_SESSION["username"]); // image file directory $target = "images/".basename($image); if(!empty($_FILES['image']['name'])) { $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby, image = :image"; }else{ $sql = "UPDATE users SET name = :name, email = :email, phone = :phone, address = :address, license_number = :license_number, position = :position, role = :role, submittedby = :submittedby"; } $stmt= $db->prepare($sql); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { $msg = "Image uploaded successfully"; }else{ $msg = "Failed to upload image"; } if(!$stmt){ if ($stmt->execute()){ $message = ' <i class="fa fa-check text-danger"> Something went wrong please contact the server admin.</i>'; } else{ $message = ' <i class="fa fa-check text-success"> Record Updated!</i>'; } } } Any help folks would be appreciated
-
Working. Mate you are a legend. $sql = "INSERT INTO timesheets (user_id, week_ending, timesheet_comment) VALUES ('$user_id', '$week_ending', '$timesheet_comment')"; if (mysqli_multi_query($con, $sql)) { $last_id = $con->insert_id; } $sql2 = "INSERT INTO stafftime (sheet_id, staff_date, time_start, time_end, break_time) VALUES ('$last_id', '$staff_date', '$time_start', '$time_end', '$break_time')"; if (mysqli_multi_query($con, $sql2)) { $message = '<p class="text-success"><i class="fa fa-check"></i> - Timesheet Submitted Successfully</p>'; } else { $message = '<p class="text-danger"><i class="fa fa-check"> Error:'. $sql2 . '<br>' . mysqli_error($con).'</p>'; } mysqli_close($con); }
-
That's what I was wondering how I do. How do I get those IDs to be the same in different tables? I did search Google about that but could find nothing.
-
*Red Faced* Sorry. I thought you meant a Var dump Here you go. Hope this is what you are after: CREATE TABLE `stafftime` ( `time_id` int(11) NOT NULL, `sheet_id` int(11) NOT NULL, `staff_date` date NOT NULL, `time_start` varchar(20) NOT NULL, `time_end` varchar(20) NOT NULL, `break_time` varchar(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `stafftime` -- INSERT INTO `stafftime` (`time_id`, `sheet_id`, `staff_date`, `time_start`, `time_end`, `break_time`) VALUES (1040, 141826, '2021-09-19', '06:00', '17:00', '1:00'), (1041, 671766, '2021-09-19', '09:30', '17:30', '1:00'), (1042, 1080, '2021-09-19', '09:30', '17:30', '1:00'); -- -------------------------------------------------------- -- -- Table structure for table `timesheets` -- CREATE TABLE `timesheets` ( `timesheet_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `week_ending` datetime NOT NULL, `timesheet_comment` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `timesheets` -- INSERT INTO `timesheets` (`timesheet_id`, `user_id`, `week_ending`, `timesheet_comment`) VALUES (1050, 9, '2021-10-10 00:00:00', 'Just a test'), (1051, 9, '2021-09-19 00:00:00', 'Just a test'), (1052, 9, '2021-09-19 00:00:00', 'Just a test'); -- -- Indexes for dumped tables -- -- -- Indexes for table `stafftime` -- ALTER TABLE `stafftime` ADD PRIMARY KEY (`time_id`), ADD KEY `timesheet_id` (`sheet_id`); -- -- Indexes for table `timesheets` -- ALTER TABLE `timesheets` ADD PRIMARY KEY (`timesheet_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `stafftime` -- ALTER TABLE `stafftime` MODIFY `time_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1043; -- -- AUTO_INCREMENT for table `timesheets` -- ALTER TABLE `timesheets` MODIFY `timesheet_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1053; COMMIT;
-
Here is a var_dump of the $result object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(12) ["lengths"]=> array(12) { [0]=> int(1) [1]=> int(4) [2]=> int(19) [3]=> int(1) [4]=> int(7) [5]=> int(0) [6]=> int(0) [7]=> int(0) [8]=> int(0) [9]=> int(0) [10]=> int(0) [11]=> int(0) } ["num_rows"]=> int(3) ["type"]=> int(0) } And a var_dump of $sql string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" string(494) "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=9" I really appreciate your time and effort man.
-
Thanks mate. Great reading. Very informative. It appears my query is not getting the data from stafftime. Populating from the other two tables fine but anything from stafftime is just not happening. $session = $_SESSION['ID']; $sql = "SELECT timesheets.user_id, timesheets.timesheet_id, timesheets.week_ending , users.id, users.name , stafftime.time_id, stafftime.sheet_id, stafftime.staff_date, stafftime.time_end, stafftime.time_start, stafftime.break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN stafftime ON stafftime.sheet_id = timesheets.timesheet_id WHERE id=$session"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) {
-
You will probably need something like this. But will need to work out the actual outline of the Frame to make it look like a TV: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_responsive_iframe_169
-
if(isset($row['time_start']) && $row['time_end'] && $row['break_time'] != "") { $time_start = new DateTime($row['time_start']); $time_end = new DateTime($row['time_end']); list($h, $m) = explode(":", $row['break_time']); $break_time = new DateInterval("PT{$h}H{$m}M"); $time_worked = $time_start->add($break_time)->diff($time_end); echo $time_worked; } Have also tried this and nothing.
-
Howdy guys, First of all, thanks so much for your help so far, especially yesterday. My wife and kids would tell you I was ropeable. Following Barand's advice and idea on my previous post, I have decided to break things up and put them into separate tables to make it easier to process. All is working fine but Hours Worked do not WERK (work), I am trying an accent Here's the code that called the timesheet submitted by a driver for one day. It is showing to the submitter based on their session id. $session = $_SESSION['ID']; $sql = "SELECT timesheets.*, users.*, staff_time.*, timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN staff_time ON timesheets.timesheet_id = staff_time.sheet_id WHERE id=$session"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Here is where I am trying to display the hours worked: <td><?php echo $row['hrs_worked']; ?></td> But nothing shows. No errors, nothing in Console either. I am obviously doing this wrong. As mentioned in my last post, I am new to this JOIN thingy-ma-jig. I know this following piece is meant to calculate between start, end and break. Not sure if that's happening either. timediff(timediff(time_end, time_start), break_time) as hrs_worked Any guidance, as always is appreciated.
-
Probably years ago lol
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
Got it: $sql = "SELECT timesheets.*, users.*, staff_time.*, timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM timesheets LEFT JOIN users ON timesheets.user_id = users.id LEFT JOIN staff_time ON timesheets.timesheet_id = staff_time.timesheet_id"; $result = $con->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { Thanks guys for your patience etc. Had never heard of JOIN this and that until it was mentioned on these forums a couple months ago :D
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with: