Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. You need to add keys "P" and "A" to the $emptyRow array and increment those. $rowdata[$s]++; You'll also need to add the two headings to the table headings row.
  2. Before doing anything with the uploaded file, check $_FILES['photo']['error'] value
  3. If you are after a specific line use file instead of file_get_contents. This will give you an array of lines in the file.
  4. Added a few lines <?php $sql = "SELECT DISTINCT date FROM attendance ORDER BY DATE"; $res = $db->query($sql); // mysqli query while ($row = $res->fetch_row()) { $dates[] = $row[0]; } /*********************************** * Table headings * ************************************/ $emptyRow = array_fill_keys($dates,''); // create arrays for "absent" and "present" $present = $absent = array_fill_keys($dates, 0); // ADD LINE // format dates foreach ($dates as $k=>$v) { $dates[$k] = date('d-M', strtotime($v)); } $heads = "<table border='1'>\n"; $heads .= "<tr><th>Name</th><th>" . join('</th><th>', $dates) . "</th></tr>\n"; /*********************************** * Main data * ************************************/ $sql = "SELECT date, staffname, status FROM attendance ORDER BY staffname"; $res = $db->query($sql); $curname=''; $tdata = ''; while (list($d, $sn, $s) = $res->fetch_row()) { if ($curname != $sn) { if ($curname) { $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; } $rowdata = $emptyRow; $curname = $sn; } $rowdata[$d] = $s; switch ($s) { // ADD THIS SWITCH STATEMENT case 'P' : $present[$d]++; break; default: $absent[$d]++; } } $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; // present and absent totals // ADD THESE LINES $tdata .= "<tr><td>PRESENT</td><td>" . join('</td><td>', $present). "</td></tr>\n"; $tdata .= "<tr><td>ABSENT</td><td>" . join('</td><td>', $absent). "</td></tr>\n"; $tdata .= "</table\n"; ?>
  5. Do you mean absent and present on each date?
  6. Thank you for sharing the solution for others having a similar problem. How many times have you googled a problem only to find the same question many times but no actual solution?
  7. use the equivalent odbc functions (odbc_exec(), odbc_fetch_row() etc). The first thing to do is get the dates that you want to show on the report. These have two purposes: 1. the headings for the report 2. keys for an array so you can store the totals for each stock code in the array Loop through the query results Test for when the stock code changes and output the stored array for the last code. Reset the array and the previous code value. Store the total in the array for this stock code/date end loop Output the array that is still stored for the last code
  8. Then GROUP BY job_type, month
  9. try something like $data = json_decode($str, true); echo "<pre><p>{$data['tide']['tideInfo'][0]['tideSite']}</p>"; $units = $data['tide']['tideInfo'][0]['units']; foreach ($data['tide']['tideSummary'] as $tidedata){ echo $tidedata['date']['pretty'] . ' ' ; if ($tidedata['data']['height']) { echo floatval($tidedata['data']['height']) . " $units "; } echo $tidedata['data']['type'] . '<br/>' ; } echo '</pre>;
  10. It was working when it left the factory After running it twice I had mysql> SELECT * FROM test.hari_libur -> ORDER BY keterangan, tgl_libur; +----+------------+---------------------------+--------+ | id | tgl_libur | keterangan | ulangi | +----+------------+---------------------------+--------+ | 4 | 2012-08-19 | Hari raya Idul Fitri | 0 | | 5 | 2012-08-20 | Hari Raya Idul Fitri | 0 | | 1 | 2010-12-25 | Hari Raya Natal | 1 | | 6 | 2011-12-25 | Hari Raya Natal | 1 | | 10 | 2012-12-25 | Hari Raya Natal | 1 | | 2 | 2010-08-17 | Proklamasi Kemerdekaan RI | 1 | | 7 | 2011-08-17 | Proklamasi Kemerdekaan RI | 1 | | 11 | 2012-08-17 | Proklamasi Kemerdekaan RI | 1 | | 3 | 2010-01-01 | Tahun Baru Masehi | 1 | | 8 | 2011-01-01 | Tahun Baru Masehi | 1 | | 9 | 2012-01-01 | Tahun Baru Masehi | 1 | +----+------------+---------------------------+--------+
  11. AFAIK regardless of the PHP version, if you want to access a version of SQL SERVER 2005 or later you need the sqlsrv extension as the mssql no longer works
  12. running this query should do it INSERT INTO hari_libur (tgl_libur, keterangan, ulangi) SELECT MAX(tgl_libur) + INTERVAL 1 YEAR , keterangan , 1 FROM hari_libur WHERE ulangi = 1 GROUP BY CONCAT(MONTH(tgl_libur),DAY(tgl_libur));
  13. fetch_array() gets the data twice in the array (one with numeric indexes and also with field names as indexes). Use fetch_assoc() or fetch_row() to only get the data once, or use optional parameter with fetch_array()
  14. TIMESTAMP will automatically record the date added. Did you specify the default? $sql = "CREATE TABLE date_sample ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, name VARCHAR(25) )"; #$db->query($sql); $sql = "INSERT INTO date_sample (name) VALUES ('Peter'),('Paul'),('Mary')"; $db->query($sql); mysql> SELECT * FROM date_sample; +----+---------------------+-------+ | id | date_added | name | +----+---------------------+-------+ | 1 | 2014-01-16 20:57:22 | Peter | | 2 | 2014-01-16 20:57:22 | Paul | | 3 | 2014-01-16 20:57:22 | Mary | +----+---------------------+-------+ If you want to record the datetime of updates also, use DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  15. As well as the three files in that zip it also requires moonphase .php which does the hard work calculating the data needed to draw the images. I didn't include it in the zip as the guy who started that topic already had it. I've attached it here. moon.php draws a single image (using moonpic100.gd2 as base image) based on the date passed in the url or today if no date passed. moonsample.php calls moon.php to draw the moon for each day of the current month. moonphase.php
  16. When you use GROUP BY staff_id you get a single row for each staff. Aggregates (eg SUM) and data which relates to a single staff id (such as name, and icon) will also be OK. The problem is where you have many records related to that staff if as in the sales_league table - you can only pull data from one of them unless you aggregate (eg SUM(money_received), MAX(date_added) etc. As Mac_gyver asked, what are you trying to achieve?
  17. The output only requires the stock_code, ship-date and qty so those are the only fileds you need to select. You can then do a GROUP BY stock_code and date to get the totals. SELECT , SysproCompanyJ.dbo.SorMaster.ReqShipDate, SysproCompanyJ.dbo.SorDetail.MStockCode, SUM(SysproCompanyJ.dbo.SorDetail.MBackOrderQty) as total FROM .... WHERE ... GROUP BY SysproCompanyJ.dbo.SorDetail.MStockCode,SysproCompanyJ.dbo.SorMaster.ReqShipDate The method to produce the table ouput would be the same as this reply earlier http://forums.phpfreaks.com/topic/285398-pivot-table-or-cross-tab-in-php-using-mysql-for-attendance/?do=findComment&comment=1465388
  18. If the VALUES provides a value for every column in the table in the correct order then there is no need to specify the column names. However, as you suggest, it is better to do so. If the table is subsequently altered the the query will fail if the columns are not specified.
  19. The tells us nothing. It what way is "not working". Do you get any results displayed? Do you get any errors? Do you have error_reporting turned on? Do you get an error from mysqli_error?
  20. Telling us you table structure would help
  21. Here's my method for reports like that $sql = "SELECT DISTINCT date FROM attendance ORDER BY DATE"; $res = $db->query($sql); // mysqli query while ($row = $res->fetch_row()) { $dates[] = $row[0]; } /*********************************** * Table headings * ************************************/ $emptyRow = array_fill_keys($dates,''); // format dates foreach ($dates as $k=>$v) { $dates[$k] = date('d-M', strtotime($v)); } $heads = "<table border='1'>\n"; $heads .= "<tr><th>Name</th><th>" . join('</th><th>', $dates) . "</th></tr>\n"; /*********************************** * Main data * ************************************/ $sql = "SELECT date, staffname, status FROM attendance ORDER BY staffname"; $res = $db->query($sql); $curname=''; $tdata = ''; while (list($d, $sn, $s) = $res->fetch_row()) { if ($curname != $sn) { if ($curname) { $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; } $rowdata = $emptyRow; $curname = $sn; } $rowdata[$d] = $s; } $tdata .= "<tr><td>$curname</td><td>" . join('</td><td>', $rowdata). "</td></tr>\n"; $tdata .= "</table\n"; ?> <html> <head> <style type="text/css"> td { text-align: center; } table { border-collapse:collapse; } </style> </head> <body> <?php echo $heads; echo $tdata; ?> </body> </html> Your dates (dd-mm-yyyy) are unusable in a database. Store as type DATE format YYYY-MM-DD so they can be correctly sorted or compared.
  22. Have you checked for an error? if (!$result) echo mysqli_error($con);
  23. Bear in mind that data from the league table that is not aggregated will be meaningless with the group by. It normally takes the values from the first record in each group but the manual states unspecified values.
  24. It's adding all 2014 amounts - total = 17,000 You have an aggregation query without a GROUP BY so you only get 1 row returned, containing data from the first row. All the columns selected other then the SUM are superfluous if you only want the total for the year
  25. mysql_select_db($db) on line 9 of reply #4
×
×
  • 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.