Jump to content

Barand

Moderators
  • Posts

    24,615
  • Joined

  • Last visited

  • Days Won

    835

Everything posted by Barand

  1. Why not heed the reply you got last time you posted this link?
  2. which translates to if (one or more of the fields has something in it) { // do nothing } else { // process the data } It is far better to put a unique constraint on your email column and then insert the record to see if it fails with a duplicate key error.. it saves a query to see if it's there Just because you didn't find it doesn't mean it won't be there when you do your insert (some could have beaten you to it).
  3. At its most basic (standard days and no holidays) you have something like this SELECT ot.task_id , tt.duration_hours , ot.start_timestamp , start_timestamp + INTERVAL (duration_hours DIV 7.5) DAY -- whole days + INTERVAL 60 * (duration_hours - (duration_hours DIV 7.5)*7.5) MINUTE -- remaining portion on final day as end_timestamp , . . . Example mysql> select '2020-06-23 08:00:00' -> + INTERVAL (9 DIV 7.5) DAY -> + INTERVAL 60 * (9 - (9 DIV 7.5)*7.5) MINUTE -> as end_time; +---------------------+ | end_time | +---------------------+ | 2020-06-24 09:30:00 | +---------------------+ Now you have a planned start and end you can look for holiday periods (and weekends) that overlap this work period. Here there are two conditions: holiday start <= start_timestamp task delayed, start_timestamp becomes the holiday end date but actual duration remains the same holiday start > start_timestamp work is interrupted for the duration of the whole holiday so holiday duration is added to task actual duration When you deviate from standard length days though, it becomes a whole lot more complex as each day's length and breaks (if applicable) need to be considered separately
  4. Suppose a task takes 10 hours. They start at 08:00 on day 1, take a 30 min break (12:30 - 13:00) then work until 16:00. They have now done 7.5 hours with 2.5 hour to go. Day2, starts at 08:00 but at 09:30 they have done another 4.5 hours on that task so break until 10:00 and finishes the task at 11:00. On to the next task - at 15:30 is due another break after 4.5 hours work so has break and goes home at 16:00 having had two breaks that day (7 hours work)
  5. Do all users always work the same hours every day? EG Wednesday 08:00 - 12:00 = short day and no break) What if a boiler installation starts at 3pm on a Friday?
  6. That query doesn't require preparation - there are no user-provided values. Also your use of single quotes around the column aliases is wrong, and you have a comma missing after B1 $sel_query = "SELECT S1 , B1 , SUM(S1 = 'Accepted') `Accepted` , SUM(S1 = 'Rejected') `Rejected` , SUM(S1 = 'Under Review') `Under_Review` FROM Enrol"; $result = $conn->query($sel_query);
  7. One way is... $secs = 350000; $dt1 = new DateTime(); $dt2 = (clone $dt1)->add(new DateInterval('PT'.$secs.'S')); $diff = $dt1->diff($dt2); echo $diff->days . ' : ' . $diff->format('%h : %i : %s').'<br>'; //-> 4 : 1 : 13 : 20
  8. What are the rules for this calculation? If your working days are 8 - 4, that's at least 5 tea-breaks
  9. I too prefer always to have the ";" at the statement ends in the main code but I don't bother with it when I use something like <?= $username ?>
  10. SELECT total as c , id , owner FROM cities CROSS JOIN ( SELECT COUNT(*) as total FROM cities WHERE owner IN (21, 37) ) tot WHERE owner IN (21, 37); What determines that those owner ids being searched for should be 21 and 37? Are they the result of another query (to find those in a "set")?
  11. Perhaps if you gave us some sample input data and then tell us what your desired output is from that data. Then we might understand what you mean.
  12. Barand

    help mee

    @roirc https://translate.google.com/ Use it before posting Folosiți-o înainte de a posta
  13. Are you now telling us that the php code that wasn't working was in a .html file and not in a .php file?
  14. $url = $row(['image_url']); ^ ^ remove ()s are for functions []s are for arrays It thinks you want to call a function called $res()
  15. @StevenOliver The final ";" before a "?>" is optional; the end of statement is implied.
  16. Yes, it's infuriating when it does what you tell it to do and not what you want it to do fwrite($contents, $number); ^ ^ number entered If you want N numbers when the user enter N, why are you always looping from 1 to 1000? Why two file opens?
  17. Try a combination approach, increasing the contrast to reduce the noise.
  18. Have you tried $im = imagecreatefromjpeg('../images/celule.jpg'); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_CONTRAST, -1000); header("Content-type: image/jpeg"); imagejpeg($im); imagedestroy($im); Emulating you matlab example $im = imagecreatefromjpeg('../images/celule.jpg'); imagefilter($im, IMG_FILTER_GRAYSCALE); $white = imagecolorallocate($im, 255,255,255); $black = imagecolorallocate($im, 0,0,0); $w = imagesx($im); $h = imagesy($im); for ($x=0; $x<$w; $x++) { for ($y=0; $y<$h; $y++) { $c = imagecolorat($im, $x, $y); if ($c & 0xFF > 190) // blue component imagesetpixel($im, $x, $y, $white); else imagesetpixel($im, $x, $y, $black); } } header("Content-type: image/jpeg"); imagejpeg($im); imagedestroy($im); Gives an effect like this (top-left corner of image)
  19. Your code is about 15 years out-of-date. As a minimum, replace "var" with "public" rename the function "publish(") to "__construct()"
  20. You need to follow the chain of keys to the required value echo $contacts[1][1]['isPublished']; or foreach ($contacts[1][1] as $key => $value) { if (!is_array($value) { echo "$key : $value <br>"; } }
  21. That would depend on the code get the query results
  22. Alternatively, define your monetary amount columns as decimal(). This gives fixed number of decimal places. Here's an example DATA CREATE TABLE `income` ( CREATE TABLE `expense` ( `income_id` int(11) NOT NULL AUTO_INCREMENT, `expense_id` int(11) NOT NULL AUTO_INCREMENT, `userid` int(11) DEFAULT NULL, `userid` int(11) DEFAULT NULL, `pay_date` date DEFAULT NULL, `expend_date` date DEFAULT NULL, `amount` decimal(10,2) DEFAULT NULL, `expamount` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`income_id`), PRIMARY KEY (`expense_id`), KEY `idx_income_userid` (`userid`) KEY `idx_expense_userid` (`userid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8; income expense +-----------+--------+------------+---------+ +------------+--------+-------------+-----------+ | income_id | userid | pay_date | amount | | expense_id | userid | expend_date | expamount | +-----------+--------+------------+---------+ +------------+--------+-------------+-----------+ | 1 | 1 | 2020-01-01 | 2500.00 | | 1 | 1 | 2020-01-15 | 800.00 | | 2 | 1 | 2020-02-01 | 2650.00 | | 2 | 1 | 2020-01-25 | 250.00 | | 3 | 1 | 2020-03-01 | 2400.00 | | 3 | 2 | 2020-01-21 | 1500.00 | | 4 | 2 | 2020-01-01 | 3000.00 | | 4 | 2 | 2020-02-10 | 500.00 | | 5 | 2 | 2020-02-01 | 3100.00 | | 5 | 2 | 2020-03-15 | 1800.00 | | 6 | 2 | 2020-03-01 | 2800.00 | | 6 | 2 | 2020-03-20 | 1600.00 | +-----------+--------+------------+---------+ +------------+--------+-------------+-----------+ QUERY SELECT i.userid , mname , income , expense , income - expense as diff FROM ( SELECT userid , EXTRACT(YEAR_MONTH from pay_date) as month , MONTHNAME(pay_date) as mname , SUM(amount) as income FROM income GROUP BY userid, month ) i LEFT JOIN ( SELECT userid , EXTRACT(YEAR_MONTH from expend_date) as month , SUM(expamount) as expense FROM expense GROUP BY userid, month ) e USING (userid, month); +--------+----------+---------+---------+---------+ | userid | mname | income | expense | diff | +--------+----------+---------+---------+---------+ | 1 | January | 2500.00 | 1050.00 | 1450.00 | | 1 | February | 2650.00 | NULL | NULL | | 1 | March | 2400.00 | NULL | NULL | | 2 | January | 3000.00 | 1500.00 | 1500.00 | | 2 | February | 3100.00 | 500.00 | 2600.00 | | 2 | March | 2800.00 | 3400.00 | -600.00 | +--------+----------+---------+---------+---------+
  23. You would use a query with a JOIN between the two tables to get the result SELECT FORMAT(i.amount - e.expamount, 2) as diff FROM incomeuser1 i JOIN expenseuser1 e ON i.whatever = e.whatever In your php code, apply a different css class if the diff value is -ve edit; When I see tables with a number suffix in their name I have doubts about the database design.
  24. Take your pick SQL SELECT FORMAT(SUM(EXPAMOUNT), 2) as exptotal PHP $x = 5.5; echo sprintf("%0.2f", $x) . '<br>'; //--> 5.50 echo number_format($x, 2); //--> 5.50
  25. Perhaps if (!file_exists($dest)) { //prevent file overwriting if (copy($url, $dest)) { $notify.= 'image saved: '. $row(['image_url']); $count++; } else { $notify.= 'ERROR saving image: '. $row(['image_url']); } } else { $notify.= 'image already exists: '. $row(['image_url']); }
×
×
  • 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.