Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. If you want historical pricing then you want a price table like price DECIMAL(10,3), valid_from DATE, valid_to DATE The current price would have valid_to date of 9999-12-31. When you add a new price from, say, tomorrow, then the current price valid_to is set to today and the new price becomes the current_price (from tomorrow until 9999-12-31) You then match your (old) items like this SELECT item_desc , qty , price FROM item INNER JOIN prices ON item.date BETWEEN prices valid_from AND prices.valid_to
  2. Do you mean something like this? SELECT * FROM ( SELECT date , price , @seq:=@seq+1 as seq FROM tablename JOIN (SELECT @seq:=0) as init ORDER BY date DESC ) sequence WHERE seq = 2 OR date = '$XXX' [edit] This does seem an odd solution to a problem. What is the actual situation and the problem you are trying to solve?
  3. It is a keyword but it is not reserved, therefore permitted as an identifier http://dev.mysql.com/doc/refman/5.5/en/keywords.html
  4. BTW, there is no "active_specialty" column Does this do it? SELECT C.yrwk , sum(slab) as slab , sum(dried_in) as dried_in , sum(drywall) as drywall , sum(frame) as frame FROM ( (SELECT DATE_FORMAT(l.frame_date, '%X-%V') as yrwk, null as slab, null as drywall, COUNT(IF(l.frame_date is not null, 1, 0)) AS frame, null AS dried_in FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = 2 ) AND l.active=1 AND l.lot_type_id <> 1 and l.frame_date is not null and (frame_date <= CURDATE() and frame_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by yrwk ) UNION ALL (SELECT DATE_FORMAT(l.drywall_date, '%X-%V') as yrwk, null as slab, COUNT(IF(l.drywall_date is not null, 1, 0)) AS drywall, null as frame, null AS dried_in FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = 2 ) AND l.active=1 AND l.lot_type_id <> 1 and l.drywall_date is not null and (drywall_date <= CURDATE() and drywall_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by yrwk ) UNION ALL (SELECT DATE_FORMAT(l.slab_date, '%X-%V') as yrwk, COUNT(IF(l.slab_date is not null, 1, 0)) AS slab, null as drywall, null as frame, null AS dried_in FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = 2 ) AND l.active=1 AND l.lot_type_id <> 1 and l.slab_date is not null and (slab_date <= CURDATE() and slab_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by yrwk ) UNION ALL (SELECT DATE_FORMAT(l.dried_in_date, '%X-%V') as yrwk, null AS slab, null as drywall, null as frame, Count(IF(l.dried_in_date is not null, 1 , 0)) AS dried_in FROM lot as l INNER JOIN lot_type AS lt ON l.lot_type_id = lt.lot_type_id INNER JOIN block as b ON b.block_id=l.block_id INNER JOIN community as c ON c.community_id=b.community_id WHERE ( c.contract_type_id = 1 OR c.contract_type_id = 2 ) AND l.active=1 AND l.lot_type_id <> 1 and dried_in_date is not null and (dried_in_date <= CURDATE() and dried_in_date >= DATE_ADD(DATE_ADD(CURDATE(),INTERVAL -11 month), interval -(day(DATE_ADD(CURDATE(),INTERVAL -11 month)) - 1) day)) GROUP by yrwk ) ) as C GROUP BY C.yrwk;
  5. "lot_type" table?
  6. Does this help? SELECT DATE_FORMAT(frame_date, '%X-%V') as yr_wk WHERE frame_date > CURDATE() - INTERVAL 6 MONTH will give you the YYYY-WW year and week number (weeks beginning Sunday) for the last six months. Much easier than all those case statements.
  7. Also, $retvalran['sstud_id'] does not exist - the column name is 'stud_id' and not 'sstud_id'. If you are just transferring data from students table to newstudent table then all you need is a single query INSERT INTO newstudent (stud_id, name) SELECT stud_id, namestud FROM students
  8. Moving to Application Design forum. I would use a 36 hour day instead of a 24 hr day. If the end time < start time, add 24hr to end time (so 20:00 - 04:00 becomes 20:00 - 28:00) Now you can have a shift/booking as a single div as before | | 00 04 08 12 16 20 00 04 08 12 | | | | | +-----------+ | |20:00-28:00| | +-----------+ | | | +-----------+ | | |09:00-16:00| | | +-----------+ | | | | |
  9. If you still want the records but not show the date when it is 0000-00-00 then SELECT t1.`id_plano` , t1.`atividade` , NULLIF(t1.`data_prevista`, 0) as `data_prevista FROM `new_pae` AS t1 WHERE t1.`id_user` = '$idUser' AND t1.`data_prevista` <= CURDATE() AND (t1.`realizado` IS NULL OR LENGTH(t1.`realizado` ) =0) or just insert null dates instead of 0000-00-00 from the outset
  10. if you run this query SELECT * FROM zamjene_brojeva WHERE glavni_broj='966 45 19-68' does it list those four records?
  11. Firstly, given that this is an example of the html code generated by your script <select name="choosecost1" size="1" value=""> <option value=""></option> <option value="200" selected="selected" ='selected="selected" '="">Cost:$200.00</option> <option value="100" =''="">Cost to Members:$100.00</option> </select> I am surprised it worked at all. Secondly, php scripts each have their own individual scope. Defining a variable on page 2 does not define it for you on page 1. The only thing I can think of, off the top of my head, is that it relied on register_globals being set (which was already obsolete 10 years ago)
  12. Just swap the $a and $b round uasort($data, function($a, $b) { $total = $b['total'] - $a['total']; //SORT BY DESC if($total === 0) { return strcmp($a['emp'], $b['emp']); // THIS line now sorts by ASC } return $total; });
  13. Do you have more than one record for each employee in the EmployeeDetails table. You probably need to join on empid and formid
  14. Don't post the same question in different forums. Closing this one.
  15. Position looks fine - after accumulating the data into the array but before outputting the data from the array. If you are getting repeated items it could be the data. Can you post the output from echo '<pre>',print_r($data, true),'</pre>';
  16. That looks very much like MS SQL Server to me.
  17. Are you formatting the price fields with commas in the query? If so 1,850.00 is treated as 1 by PHP (up to the first non-numeric character)
  18. $grandTotal = 0; // initialise to 0 while (odbc_fetch_row($result)) { $scanner=odbc_result($result,"tuser"); $Item=odbc_result($result,"item"); $Qty=odbc_result($result,"qty"); $Price=odbc_result($result,"TotalPrice"); $grandTotal += $price; // accumulate price echo "<tr><td>$scanner</td>"; echo "<td> ◃ </td>"; echo "<td>$Item</td>"; echo "<td> ▹ </td>"; echo "<td>$Qty</td>"; echo "<td align='right'>$Price</td></tr>"; } echo "Grand Total: $grandTotal"; // output grand total
  19. You have only defined the function to validate input, you haven't called it
  20. Test data +------------------+-------+---------+----------+---------+ | submittedform_id | empid | empname | formname | scoring | +------------------+-------+---------+----------+---------+ | 1 | 1 | James | Form A | 4 | | 2 | 1 | James | Form B | 9 | | 3 | 1 | James | Form C | 8 | | 4 | 2 | Foo | Form A | 12 | | 5 | 2 | Foo | Form D | 10 | | 6 | 3 | bar | Form C | 30 | | 7 | 3 | bar | Form A | 5 | | 8 | 4 | Peter | Form B | 10 | | 9 | 4 | Peter | Form C | 4 | | 10 | 5 | Paul | Form A | 5 | | 11 | 5 | Paul | Form D | 12 | | 12 | 5 | Paul | Form B | 8 | | 13 | 6 | Mary | Form A | 9 | | 14 | 6 | Mary | Form B | 11 | | 15 | 7 | Jenny | Form B | 15 | | 16 | 7 | Jenny | Form C | 8 | | 17 | 8 | Steve | Form B | 9 | | 18 | 8 | Steve | Form D | 15 | | 19 | 9 | Tom | Form A | 12 | | 20 | 9 | Tom | Form C | 8 | | 21 | 10 | Zak | Form C | 9 | | 22 | 10 | Zak | Form D | 8 | +------------------+-------+---------+----------+---------+ 10 employees therefore top 20% are the two with highest scores SELECT sf.empid , sf.empname , sf.formname , sf.scoring , total , rank , pos , numemps FROM submittedform sf INNER JOIN ( SELECT empid , total , @pos := @pos + 1 as pos , @rank := IF(total=@prevtot, @rank, @pos) as rank , @prevtot := total FROM ( SELECT empid , SUM(scoring) as total FROM submittedform INNER JOIN (SELECT @pos:=0, @rank:=1,@prevtot:=0) as init GROUP BY empid ORDER BY SUM(scoring) DESC ) tot ) posn ON sf.empid = posn.empid CROSS JOIN ( SELECT COUNT(DISTINCT empid) as numemps FROM submittedform ) as ct WHERE CEIL(rank*100/numemps) <= 20 ORDER BY total DESC; +-------+---------+----------+---------+-------+------+------+---------+ | empid | empname | formname | scoring | total | rank | pos | numemps | +-------+---------+----------+---------+-------+------+------+---------+ | 3 | bar | Form C | 30 | 35 | 1 | 1 | 10 | | 3 | bar | Form A | 5 | 35 | 1 | 1 | 10 | | 5 | Paul | Form A | 5 | 25 | 2 | 2 | 10 | | 5 | Paul | Form D | 12 | 25 | 2 | 2 | 10 | | 5 | Paul | Form B | 8 | 25 | 2 | 2 | 10 | +-------+---------+----------+---------+-------+------+------+---------+
  21. The top 20% are not those that got 20% (or more) of the total. In your example, the top 66% got 40% (or more)
  22. http://www.w3.org/TR/WCAG20-TECHS/H76.html
  23. Assuming the data looks something like this +--------+----------+-------------+ | userid | username | childcareid | +--------+----------+-------------+ | 1 | Albert | 1 | | 2 | Betty | 2 | | 3 | Charlie | 3 | | 4 | Diane | 1 | | 5 | Edward | 2 | | 6 | Fiona | 3 | | 7 | Graham | 1 | | 8 | Helen | 2 | | 9 | Ian | 3 | | 10 | Jane | 1 | +--------+----------+-------------+ then the query you want is (if logged in user has id=1) SELECT u2.username , u2.childcareid FROM users u1 INNER JOIN users u2 USING (childcareid) WHERE u1.userid = 1 -- logged user +----------+-------------+ | username | childcareid | +----------+-------------+ | Albert | 1 | | Diane | 1 | | Graham | 1 | | Jane | 1 | +----------+-------------+
  24. NOTE: usort() above should be uasort() to preserve the empid values. This will give the top 20 % uasort($data, function($a,$b){return $b['total']-$a['total'];}); $pcent20 = ceil(count($data)/5); $data = array_slice($data, 0, $pcent20, true);
×
×
  • 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.