Jump to content
#StayAtHome ×

Barand

Moderators
  • Content Count

    20,556
  • Joined

  • Last visited

  • Days Won

    463

Everything posted by Barand

  1. 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.
  2. Barand

    php insert

    Here's a section of your form Becacause you have used checkboxes you are inviting the user to select one or more applicable options. In the example shown, a reasonable combination of "Fatal / Fire / Property Damage". However, because of the way you have named them in your code (all same name "checkbox"), your processing will only receive the last one. In this example that is the least important. To receive all the selected options, append "[]" to the checkbox names. <tr> <td><input type="checkbox" value="Nearmiss case" name="checkbox[]"></td> <td><input type="checkbox" value="First Aid Case" name="checkbox[]"></td> <td><input type="checkbox" value="Lost Time Injury" name="checkbox[]"></td> <td><input type="checkbox" value="Fatal" name="checkbox[]"></td> <td><input type="checkbox" value="Fire" name="checkbox[]"></td> <td><input type="checkbox" value="Emission/Discharge/Spill/Leak(Abnormal)" name="checkbox[]"></td> <td><input type="checkbox" value="Property Damage" name="checkbox[]"></td> <td><input type="checkbox" value="HIPO" name="checkbox[]"></td> </tr> This will then cause them to be POSTed as an array $_POST = Array ( [checkbox] => Array ( [0] => Fatal [1] => Fire [2] => Property Damage ) [btnSubmit] => Submit ) If you want the user to select only one, use radio buttons. Just my 0.02 worth.
  3. You output totals once per user. The logic would be the same for outputting the inks, but it depends where you want to output them.
  4. This is going to come as a surprise to you, but from where I am sitting I cannot see over your shoulder and look at the code on your screen. I do not what query you ran, what data your loop is processing or what your loop is outputting to the screen, or anything else it may be doing. Therefore it not possible for me to tell you what to do in your situation.
  5. Barand

    php insert

    Are you sure the two code samples you posted are related? The first processes 21 $_POST inputs, the second has 2 input fields.
  6. That query will insert 1 row. If it's inserting more than that then you are running that code more than once. Is it inside a loop that isn't shown?
  7. Have you run the code 64 times, perhaps? And what is this "join" you keep mentioning?
  8. But you know the player id, so why do you need a query to tell you what the player id is where the player id = X
  9. Barand

    php insert

    It looks like line 57 is if ($res) { No sign of name index anywhere near it.
  10. Then don't you think that query is a waste of space?
  11. Haven't you learnt yet that you can't always copy/paste code and expect it to work straight out of the box? I created a connection $db and passed that as a parameter. However, you created a connection $conn so pass that instead. $pdf = new attendPDF($db, $_GET['oracleid'], $_GET['sdate'], $_GET['edate']); ^ ^ $conn
  12. Seriously? How many records in a_players have that id?
  13. What's your code to create the new attendPDF object?
  14. The whole content of your web page changes based on choices. The link is just another bit of output. Here's an idea - try thinking.
  15. You set out with a connection called "$link" then suddenly switch to a non-existent "$conn" !? Perhaps if you read your own code?
  16. 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(); ?>
  17. That is no excuse to design db tables like spreadsheets. You can always create views for the technically challenged users. EDIT: For example there is a "fixture" table in the db in the tutorial on my site mysql> select * from fixture; +---------+----------+----------+-----------+-----------+--------+ | idmatch | hometeam | awayteam | homegoals | awaygoals | weekno | +---------+----------+----------+-----------+-----------+--------+ | 1 | 4 | 2 | 1 | 0 | 1 | | 2 | 2 | 4 | 2 | 2 | 2 | | 3 | 3 | 2 | 4 | 4 | 3 | | 4 | 1 | 3 | 1 | 1 | 1 | | 5 | 2 | 3 | 1 | 2 | 4 | | 6 | 3 | 1 | 1 | 3 | 2 | | 7 | 4 | 3 | 2 | 0 | 5 | | 8 | 2 | 1 | 0 | 3 | 5 | | 9 | 1 | 4 | 2 | 4 | 3 | | 10 | 4 | 1 | 4 | 4 | 4 | | 11 | 1 | 2 | 4 | 1 | 6 | | 12 | 3 | 4 | 1 | 4 | 6 | +---------+----------+----------+-----------+-----------+--------+ But to make it a bit friendlier, setting up a view gives mysql> select * from fixture_view; +---------+--------+----------+-----------+-----------+----------+ | idmatch | weekno | hometeam | homegoals | awaygoals | awayteam | +---------+--------+----------+-----------+-----------+----------+ | 4 | 1 | Laker | 1 | 1 | Jardine | | 1 | 1 | Cowdrey | 1 | 0 | Grace | | 6 | 2 | Jardine | 1 | 3 | Laker | | 2 | 2 | Grace | 2 | 2 | Cowdrey | | 9 | 3 | Laker | 2 | 4 | Cowdrey | | 3 | 3 | Jardine | 4 | 4 | Grace | | 10 | 4 | Cowdrey | 4 | 4 | Laker | | 5 | 4 | Grace | 1 | 2 | Jardine | | 7 | 5 | Cowdrey | 2 | 0 | Jardine | | 8 | 5 | Grace | 0 | 3 | Laker | | 12 | 6 | Jardine | 1 | 4 | Cowdrey | | 11 | 6 | Laker | 4 | 1 | Grace | +---------+--------+----------+-----------+-----------+----------+
  18. My code example defaults to 0 for both of those if they aren't set.
  19. Perhaps $cartidOK = $_SESSION['cartid'] ?? 0; $cartitemOK = $_POST['cartitem'] ?? 0 $quantityOK = isset($_POST['quantity']) && is_numeric($_POST['quantity']); $lockedcard = $_SESSION['lockedcard'] ?? 0; $lockedpaypal = $_SESSION['lockedpaypal'] ?? 0; if ( $cartidOK && $cartitemOK && $quantityOK && !$lockedcard && !$lockedpaypal) { // do it }
  20. I would have thought it better to this client-side. This example prompts for address and date moved in, then until date oder than three years is entered it prompts for a previous address <?php // HANDLE THE AJAX REQUEST if (isset($_GET['prevdate'])) { $dt = new DateTime($_GET['prevdate']); $years = $dt->diff(new DateTime())->y; if ($years >= 3) { exit("OK"); } else { exit('<div> <b>Previous Address</b><br> <input type="text" name="prevadd[]" class="prevadd" size="55"> <b>Moved in</b> <input type="date" name="prevdate[]" class="prevdate" onchange="checkDate(this)"> </div>'); } } ?> <!DOCTYPE html> <html> <head> <title>Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> function checkDate(dobj) { var date = $(dobj).val() $.get( "", {"prevdate":date}, function(resp) { if (resp != "OK") { $("#prevaddresses").append(resp) } }, "TEXT" ) } </script> <style type="text/css"> #prevaddresses { padding: 16px; border: 1px solid gray; width: 600px; margin: 16px auto; } </style> </head> <body> <h1>Example</h1> <div id="prevaddresses"> <div> <b>Address</b><br> <input type="text" name="prevadd[]" class="prevadd" size="55"> <b>Moved in</b> <input type="date" name="prevdate[]" class="prevdate" onchange="checkDate(this)"> </div> </div> </body> </html> It could be pure JS but I used ajax to take advantage of PHP's date arithmetic.
  21. Can't say as you are the only person who knows what, precisely, you are trying to specify.
  22. Make sure to use parentheses to enforce the correct logic when mixng AND with OR Instead of A AND B OR C specify (A AND B) OR C or A AND (B OR C)
  23. https://css-tricks.com/almanac/properties/p/page-break/ Or write a custom script using FPDF or similar so you have complete control
  24. Then just put that week's dates in the date table. The CROSS JOIN of staff and date gives a row for every date for each staff member that you want to check. staff date staff CROSS JOIN date ----- ----- --------------------- A 1 A 1 B 2 A 2 C 3 A 3 4 A 4 5 A 5 B 1 B 2 B 3 B 4 B 5 C 1 C 2 C 3 C 4 C 5 It then LEFT JOINS with the attendance records to see where there is no match (IE they are absent). staff CROSS JOIN date staff CROSS JOIN date attendance_record LEFT JOIN attendance_record --------------------- ----------------- --------------------------- A 1 A 1 A 1 A 1 A 2 A 3 A 2 NULL NULL A 3 A 4 A 3 A 3 A 4 A 5 A 4 A 4 A 5 B 1 A 5 A 5 B 1 B 2 B 1 B 1 B 2 B 4 B 2 B 2 B 3 B 5 B 3 NULL NULL B 4 C 1 B 4 B 4 B 5 C 2 B 5 B 5 C 1 C 3 C 1 C 1 C 2 C 5 C 2 C 2 C 3 C 3 C 3 C 4 C 4 NULL NULL C 5 C 5 C 5
×
×
  • 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.