
ramiwahdan
Members-
Posts
114 -
Joined
-
Last visited
Everything posted by ramiwahdan
-
I am using your code, i passed link from my old page to new page that has your code, the line that makes the select statement is having that error. for fpdf i am using your code with page named fpdf.php
-
Hi, you need to change $conn to $link you have: if ($conn->query($sql) === TRUE) { and have: $conn->close(); change them to if ($link->query($sql) === TRUE) { and $link->close();
-
Hi, So I put the link in my original php file and when i am directed to the fpdf page i get the first error as i am walking my way through... First my code: <?php require('fpdf/fpdf.php'); include('dbcon.php'); // ADD YOUR OWN PDO CONNECTION CODE // $servername = "localhost"; $username = "???"; $password = "???"; $db = "timeclock"; $conn = new PDO("mysql:host=$servername;dbname=$db", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); class attendPDF extends FPDF { protected $today; protected $headbase; protected $db; protected $sid; protected $name; protected $sdate; protected $edate; //constructor public function __construct($db, $oracleid, $sdate, $edate) { parent::__construct(); $this->today = date('jS M Y'); $this->db = $db; $this->sid = $oracleid; $this->sdate = new DateTime($sdate); $this->edate = new DateTime($edate); $res = $this->db->prepare("SELECT staffname FROM staff WHERE oracleid = ? "); $res->execute( [ $oracleid ] ); $this->name = $res->fetchColumn(); } and here is the error: Fatal error: Uncaught Error: Call to a member function prepare() on string in C:\xampp\htdocs\AttendanceSystem\login\fpdf.php:36 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\fpdf.php(148): attendPDF->__construct('timeclock', '533349', '2020-03-01', '2020-03-31') #1 {main} thrown in C:\xampp\htdocs\AttendanceSystem\login\fpdf.php on line 36 I confirm all info is correct so why there is an error
-
First, thanks for the big help. So i will keep my original untouched or i will only take the code you gave me? If i keep the original, what changes i need to do to that? your screenshots shows both attendance and absent tables, is if from the file you gave me? If i need to add the link you gave me to my original php file, it changes based on choices, how to get that? Lastly, I used to get the dates from a form, in your file, how are we getting these dates?
-
i am trying to use FPDF as you mention it but i am able to find out the problem. and here is what i tried: require('fpdf/fpdf.php'); $pdf = new FPDF(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Absent Report'); $pdf->SetFont('Arial','',8); and i am adding the pages at the end after displaying my data \\ code before foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <p>Absent Report:</p> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> <?php $pdf->AddPage(); $pdf->Cell(40,10,$tdata); $pdf->Output(); ?> </table> <a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html> I get this error Fatal error : Uncaught Exception: FPDF error: No page has been added yet in C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php:271 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php(1447): FPDF->Error('No page has bee...') #1 C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php(643): FPDF->_out('BT 2.83 822.92 ...') #2 C:\xampp\htdocs\AttendanceSystem\login\singlereportidfinal.php(22): FPDF->Cell(40, 10, 'Absent Report') #3 {main} thrown in C:\xampp\htdocs\AttendanceSystem\login\fpdf\fpdf.php on line 271 I am trying to put the last table (absents) in new page
-
screenshot, the data split to second page, instead i want the absent table to all move to second page in the printer
-
I have print page using window.print in the body tag at the beginning of php file and i am trying to make the rest of the code as second page, the last table will be on the second page. it is not working. code: <b>Absent Report:</b> <table style ="page-break-before: always;" border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> <a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html> why it is not working?
-
i got it when you said the word date and realized i have start date. now, can i add to that code an end date? $month = $sdate1; $start_date = new DateTime("$month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime()); can i have end date since it is taking start date?
-
i am sorry that you got upset but in my company they might search for someone for a week as example so they dont want to look the whole month.
-
no, i want to use them so i can pull out records from db only between the chosen dates.
-
i need to add between dates from a form to add to where clause and I tried this but it will return nothing, the table is empty again code: WHERE a.oracleid IS NULL and s.oracleid = '$userid' and DATE(a.ClockingOutDate) >= $sdate1 and DATE(a.ClockingOutDate) <= $edate1 sdate1 and edate1 are variables taken from form fields in the page of type date.
-
here is the whole code to see where is my mistake! why i am getting error $conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.staffname , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid = $userid ORDER BY s.oracleid, d.date "); $result = $conn->fetchAll(); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> please advise
-
I have this code that will get the absent dates for all employees, how can i make it for one specific employee using oracle id? code: $res = $conn->query("SELECT s.oracleid , s.staffname , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date "); the records i am concerned about is for the attendance records table, I have oracle id in that table.
-
Thank you very much sir, really great help and promise i will do something about it. Great
-
$tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html> if i add this i get the error, i noticed if i create normal table i am getting results but it also includes the non absent days. can you check where is the mistake? full code <?php $month = 'March'; $start_date = new DateTime("first monday of $month"); $incr = DateInterval::createFromDateString('next weekday'); $period = new DatePeriod($start_date, $incr, new DateTime()); $servername = "localhost"; $username = "???"; $password = "???"; $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password); // create temporary date table $conn->exec("CREATE TEMPORARY TABLE date (date date not null primary key)"); // populate it foreach ($period as $d) { $dates[] = "('{$d->format('Y-m-d')}')" ; } $conn->exec("INSERT INTO date VALUES " . join(',', $dates)); // now get the days absent $res = $conn->query("SELECT s.oracleid , s.name , date_format(date, '%W %d/%m/%Y') as absent FROM staff s CROSS JOIN date d LEFT JOIN attendance_records a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE a.oracleid IS NULL ORDER BY s.oracleid, d.date "); $tdata = ''; foreach ($res as $r) { $tdata .= "<tr><td>" . join('</td><td>', $r) . "</td></tr>\n"; } ?> <html> <head> <title>Example</title> <style type="text/css"> table { border-collapse: collapse; width: 600px; } th, td { padding: 8px; } th { background-color: black; color: white; } </style> </head> <body> <table border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> </body> </html> what about this, why is it null? WHERE a.oracleid IS NULL
-
Thanks, one more thing, instead of first Monday how to make it from first day, also in my country the holiday is Friday and Saturday not Saturday and Sunday, how to change that?
-
i did understand this but why i am getting empty page, i did what you did. how to show the data?
-
this is not created in the db? i am missing anything?
-
OK here is what i need as output if possible: last login: Monday 23-3-2020 today's date: Wednesday 25-3-2020 add record to db that Tuesday 24-3-2020 is absent the first 2 i am getting from records in db, how i can get the information like last line "Tuesday 24-3-2020"? then i can add to db.
-
Hi, I have db table that records the days (Sunday, Monday...) when the employee login to the system. Say that the employee logged in on Monday then Logged in on Wednesday so this means he was absent on Tuesday. I calculated the number of days to get the answer 2 (between Wednesday and Monday before logging in on Wednesday) how to get the name of the missing day "Tuesday"? code: $curdate = date("Y-m-d"); $currday = date('l'); $lastdate = $row['indate']; $lastdayin = $row['lastdayin']; if ($lastdate !=Null) { $misseddates = strtotime($curdate) - strtotime($lastdate); $misseddates = $misseddates / 86400; echo $misseddates; $misseddays = strtotime($lastdayin) - strtotime($currday); $misseddays = $misseddays / 86400; echo $misseddays; } I tried to get the name of day in the last step but it only calculates 5 in numbers how to get the name. I want the answer to be "Tuesday" as of the example. Thanks.
-
thanks for the help, here is what i tried: $fromdate = $_POST['sdate']; $todaten = $_POST['edate']; $fromdate2 = date("d-m-Y",$fromdate); $todate2 = date("d-m-Y",$todate); now getting new error: Notice : A non well formed numeric value encountered in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php on line 107 please advise? Since POST is getting a string how to convert to date?
-
I am trying to get the full date from form field using the date function and post method. $fromdate = $_POST[‘sdate’]; $todate = $_POST[‘edate’]; $fromday = date(‘F j, Y, g:i a’,’$fromdate’); $today1 = date(‘F j, Y, g:i a’,’$todate’); When trying to print i get the right format but i get extra information not sure from where? I am getting the date from the form fields of type date. Code Output: March 19, 2020, 4:16 pm,$31202019pm31Asia/Dubai why i am getting the second part!
-
I had to re-create all tables again.
-
Hi, I have select statement that will take data from form and add it to select statement but i get this error: Fatal error : Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':startdate and DATE(ClockingOutDate) <= :enddate ORDER BY o' at line 16 in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php:62 Stack trace: #0 C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php(62): PDO->query('SELECT oracleid...') #1 {main} thrown in C:\xampp\htdocs\AttendanceSystem\login\reportsbydateforall.php on line 62 this is the code: <?Php include('session.php');?> <html> <head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> </head> <body> <Center> <h2>Please enter start date and end date:</h2> </center> <form action="#" method="post"> <center> <h5>Start Date:<input type="date" name="sdate" placeholder = "Start Date" required="required"></input> End Date:<input type="date" name="edate" placeholder = "End Date" required="required"></input> <input type="submit" name="saveit" value="Generate"></input></h5> </center> </form> <div class="container"> <div class="row"> <div class="col m-auto"> <div class="card mt-5"> <table class="table table-bordered"> <tr> <input type="button" onClick="window.print()" value="Print The Report"/> <td>OracleID</td> <td>Name</td> <td>Designation</td> <td>Clocking In Time</td> <td>Clocking Out Time</td> <td>Duration</td> </tr> <?php if (isset($_POST['saveit'])) { $servername = "localhost"; $username = "rwahdan"; $password = "fatima2010"; $sdate1 = $_POST['sdate']; $edate1 = $_POST['edate']; $conn = new PDO("mysql:host=$servername;dbname=timeclock", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $res = $conn->query("SELECT oracleid , name , des , clockingindate , clockingoutdate , timediff(clockingoutdate, clockingindate) as duration , total FROM attendance_records JOIN ( SELECT oracleid , sec_to_time(sum(timestampdiff(SECOND, clockingindate, clockingoutdate))) as total FROM attendance_records where isdone =-1 GROUP BY oracleid ) tots USING (oracleid) where isdone =-1 and DATE(ClockingOutDate) >= :startdate and DATE(ClockingOutDate) <= :enddate ORDER BY oracleid, clockingindate "); $prepared=$conn->prepare($res); // bind parameters with placeholders $prepared->bindParam(':startdate',$_POST['sdate']); $prepared->bindParam(':enddate',$_POST['edate']); // execute the query $prepared->execute(); // fetch results $results=$prepared->fetchAll(); // this will return an array containing all of the rows in the result set // check for errors if ($prepared->errorCode()!=0) { die(print_r($prepared->errorInfo())); } ?> problem with where clause conditions but don't know how to deal with this issue.