Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/30/2020 in all areas

  1. You need to use parameter binding rather than variable interpolation.
    1 point
  2. Yes, i know. You already established that. In my previous post, I suggested you might be able able to output the link with each person's total (ie once per person like the total). If you want them somewhere else then the logic will be different.
    1 point
  3. Looks like you have a bit of reading to do regarding the use of FPDF. You can't just call the cell() function and output a PHP table into it. Don't mix the screen output code with FPDF code. Put the FPDF into a separate script. Display the web page and put a link to the pdf page EG <a href='attendance_pdf.php?oracleid=533349&sdate=2020-03-01&edate=2020-03-05'>Print version</a> Below is a sample FPDF script (read, learn and digest) to produce a report which looks like this ... attendance_pdf.php... <?php require('../fpdf/fpdf.php'); // ADD YOUR OWN PDO CONNECTION CODE // class attendPDF extends FPDF { protected $today; protected $headbase; protected $db; protected $sid; protected $name; protected $sdate; protected $edate; //constructor public function __construct($db, $staffid, $sdate, $edate) { parent::__construct(); $this->today = date('jS M Y'); $this->db = $db; $this->sid = $staffid; $this->sdate = new DateTime($sdate); $this->edate = new DateTime($edate); $res = $this->db->prepare("SELECT name FROM staff WHERE oracleid = ? "); $res->execute( [ $staffid ] ); $this->name = $res->fetchColumn(); } //Page header public function Header() { //Helvetica bold 12 $this->SetFont('Helvetica', '', 14); $this->Cell(0, 15, "Attendance Report", 1, 1, 'C'); //Title $sd = $this->sdate->format('l jS F Y'); $ed = $this->edate->format('l jS F Y'); $this->SetFont('Helvetica', '', 12); $this->Cell(60,15,$this->sid . ' - ' . $this->name,1,0,'L'); $this->Cell(120, 15, "$sd - $ed" , 1, 0, 'C') ; $this->Ln(); $this->headbase = $this->GetY(); } //Page footer public function Footer() { $this->setY(-22); $this->setX(15); $this->SetFont('Helvetica', '', 10); $this->Cell(0,5,'( '.$this->today.' )', 'T'); } public function attendanceReport() { $widths = [60, 60, 60]; $aligns = [ 'L', 'L', 'C' ]; $heads = ['Clocked In Time', 'Clocked Out Time', 'Duration']; $this->SetY(50); $this->SetFont('Helvetica', 'B', 12); $this->Cell(0, 10, 'Attendances', 0, 1); $this->SetFontSize(10); foreach ($heads as $k => $h) { $this->Cell($widths[$k], 10, $h, 1, 0, $aligns[$k], 1); } $this->Ln(); $this->setFont('', ''); $res = $this->db->prepare("SELECT date_format(clockingindate, '%a %d/%m/%Y %l:%i %p') as clkin , date_format(clockingoutdate, '%a %d/%m/%Y %l:%i %p') as clkout , timediff(clockingoutdate, clockingindate) as duration FROM attendance_record WHERE oracleid = ? AND DATE(clockingindate) BETWEEN ? AND ? ORDER BY clockingindate "); $res->execute([ $this->sid, $this->sdate->format('Y-m-d'), $this->edate->format('Y-m-d') ] ); while ( $r = $res->fetch(PDO::FETCH_NUM) ) { foreach ($r as $k => $v) { $this->Cell($widths[$k], 6, $v, 0, 0, $aligns[$k]); } $this->Ln(); } } public function absenceReport() { $this->SetY(50); $this->SetFont('Helvetica', 'B', 12); $this->Cell(0, 10, 'Absences', 0, 1); $this->SetFontSize(10); $this->Cell(0, 10, 'Dates Absent', 1, 0, 'L', 1); $this->setFont('', ''); $this->Ln(); // set up a temporary date table - each working day in the reporting period $this->db->exec("CREATE TEMPORARY TABLE date(date date)"); $incr = DateInterval::createFromDateString('next weekday'); $sd = clone $this->sdate; $ed = clone $this->edate; $sd->modify('+1 days'); // adjust for Islamic working week $ed->modify('+2 days'); // adjust for Islamic working week $range = new DatePeriod($sd, $incr, $ed); foreach ($range as $d) { $dt = $d->sub(new DateInterval('P1D'))->format('Y-m-d'); // adjust for Islamic working week $dates[] = "('$dt')"; } $this->db->exec("INSERT INTO date VALUES " . join(',', $dates)); // get days absent $res = $this->db->prepare("SELECT DATE_FORMAT(date, '%W %d/%m/%Y' ) as date FROM staff s CROSS JOIN date d LEFT JOIN attendance_record a ON s.oracleid = a.oracleid AND d.date = DATE(a.clockingindate) WHERE s.oracleid = ? AND a.oracleid IS NULL "); $res->execute( [ $this->sid ] ); foreach ($res as $r) { $this->Cell(0, 6, $r['date'], 0, 1); } } }# end class if (!isset($_GET['oracleid']) || !isset($_GET['sdate']) || !isset($_GET['edate'])) { exit; } // // GENERATE REPORT // $pdf = new attendPDF($db, $_GET['oracleid'], $_GET['sdate'], $_GET['edate']); $pdf->AliasNbPages(); $pdf->setAutoPageBreak(1,25); $pdf->setMargins(15,15,15); $pdf->SetDrawColor(102); $pdf->SetFillColor(220); $pdf->AddPage(); $pdf->attendanceReport(); $pdf->AddPage(); $pdf->absenceReport(); $pdf->output(); ?>
    1 point
  4. I don't know whether you care or not about People with names like "Martin St. Louis" but obviously your code will not work correctly in that case. Of course you also can't tell if it's someone with a name like 'Sue Ann Smith'. Your code is biased towards Sue Ann Smith, but gets Martin St. Louis wrong. Without a separation of first name and lastname, there is no way to really do it reliably. With that said, you can boil this down to a one liner that doesn't use arrays. I'm fairly sure that your code would throw a runtime error if there was a single name in the string, but didn't test it. This could/should be coded around, which I do with a ternary. There is a lot of extra trimming I do, which could be avoided if the original string was simply trimmed prior to using this one liner, but I provided something that works with a variety of extraneous spaces, per the examples. Here's a one liner as a function for the purposes of illustration, that you might consider: $tests = array('Bob Jones', 'Sue Ann Smith', 'Martin St. Louis', 'Prince', ' Adam West', ' Fred R. Murray ', ' Skipper Van Dammage'); foreach ($tests as $test) { echo makeName($test) . PHP_EOL; } function makeName($name) { return false !== strpos(trim($name), ' ') ? preg_replace('/\s\s+/', ' ', rtrim(substr(trim($name), 0, strrpos(trim($name), ' ')))) . ' ' . substr(strrchr(rtrim($name), ' '), 1, 1) : trim($name); } Returns: Bob J Sue Ann S Martin St. L Prince Adam W Fred R. M Skipper Van D
    1 point
  5. Yes SELECT e.entry_id , field_id , value FROM wp_wpforms_entry_fields f JOIN wp_wpforms_entries e ON f.entry_id = e.entry_id WHERE field_id IN (5, 13, 16, 18) AND e.status='completed' ORDER BY e.entry_id
    1 point
  6. DATA +----------+----------+-------+ | entry_id | field_id | value | +----------+----------+-------+ | 1 | 5 | Curly | | 1 | 13 | bbb | | 1 | 16 | ccc | | 1 | 18 | ddd | | 2 | 5 | Larry | | 2 | 13 | eee | | 2 | 16 | fff | | 2 | 18 | ggg | | 2 | 43 | hhh | | 3 | 5 | Mo | | 3 | 13 | kkk | | 3 | 16 | mmm | | 3 | 18 | nnn | | 3 | 43 | ooo | | 4 | 5 | Tom | | 4 | 13 | ppp | | 4 | 16 | qqq | | 4 | 18 | rrr | | 4 | 43 | sss | +----------+----------+-------+ CODE $res = $conn->query("SELECT entry_id , field_id , value FROM wp_wpforms_entry_fields WHERE field_id IN (5, 13, 16, 18) ORDER BY entry_id "); $headings = [ 5 => 'Name' , 16 => 'Belt' , 13 => 'School', 18 => 'Events' ]; $temp_array = array_fill_keys(array_keys($headings), ''); // array for each attendee to be filled in from query results // process query results and place in array with attendee as the key $data = []; foreach ($res as $r) { if ( !isset($data[$r['entry_id']])) { $data[$r['entry_id']] = $temp_array ; } $data[$r['entry_id']][$r['field_id']] = $r['value'] ; // store answer in its array position } $theads = "<tr><th>" . join('</th><th>', $headings) . "</th></tr>\n" ; $tdata = ''; foreach ($data as $d) { $tdata .= "<tr><td>" . join('</td><td>', $d) . "</td></tr>\n"; } OUTPUT
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • 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.