Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Efficiency. One table subquery called once versus a dependent subquery called for every row
  2. if you leave it as a time field SELECT SEC_TO_TIME(AVG(TIME_TO_SEC(post_time_dif))) as tot FROM response WHERE profile_id = '$id' job done
  3. try a JOIN Select artist from songlist inner join (Select distinct title from songlist where artist='Bob Dylan') as dylan using (title)
  4. What format / column type is post_time_dif?
  5. If you look at your other post about these media arrays you'll see I already posted a better way. Are you planning many more posts on this same topic?
  6. if(STORE_MIN_DELIVERY !=0 && STORE_MIN_DELIVERY !=NULL )
  7. $variable is available only inside that method, Read up on variable scope. $this->variable is available to other methods throughout the class, and (as it declared public) to other classes.
  8. If I understand while ($row = mysqli_fetch_assoc($result) { $media[$row['id']] = $row; }
  9. $array_1 = array("1","2","2","3"); $array_2 = array("1","2"); //count how many 1s ands 2s are in total $counts = array_count_values($array_1); $tot = 0; foreach ($array_2 as $n) { $tot += $counts[$n]; } echo $tot;
  10. I gave him the query, can't understand what there is left to be stuck on
  11. that gives highest first
  12. Make your dates type DATE in the database (format yyyy-mm-dd) and your input dates in the same format and then you stand a chance of getting it to work. When you've done that you can use date arithmetic, comparisons and MySql date and time functions.
  13. SELECT name, COUNT(*) as tot FROM table GROUP BY name ORDER BY tot LIMIT 1
  14. What format are your dates?
  15. Id create a table of staff, each one storing the id of their boss $db = new mysqli(HOST, USERNAME, PASSWORD, 'test'); /* data ***************************************************/ $sql = "CREATE TABLE employee ( empid INT NOT NULL AUTO_INCREMENT PRIMARY KEY, empname varchar(50), managerid INT )"; $db->query($sql); $sql = "INSERT INTO employee (empid,empname,managerid) VALUES (1, 'Boss', 0), (2, 'Area Mgr 1', 1), (3, 'Area Mgr 2', 1), (4, 'Team Ldr 1A', 2), (5, 'Team Ldr 1B', 2), (6, 'Team Ldr 2A', 3), (7, 'Team Ldr 2B', 3), (8, 'Emp 1A1', 4), (9, 'Emp 1A2', 4), (10, 'Emp 1B1', 5), (11, 'Emp 1B2', 5), (12, 'Emp 2A1', 6), (13, 'Emp 2A2', 6), (14, 'Emp 2B1', 7), (15, 'Emp 2B2', 7)"; $db->query($sql); You can then do recursive search to find all employees in their part of the hierarchy $userid = 3; // current user $subords = array($userid); findSubordinates($userid, $subords, $db); // search for rubordinates // // recursive search // function findSubordinates ($id, &$canview, $db) { $sql = "SELECT empid FROM employee WHERE managerid = $id"; $res = $db->query($sql); while (list($emp) = $res->fetch_row()) { $canview[] = $emp; findSubordinates($emp, $canview, $db); } } Thenyou can retrieve the data for all employees in the list $emplist = join(',', $subords); $sql = "SELECT emp.empid , emp.empname , timesheet.date_workd , timesheet.hrs FROM employee as emp INNER JOIN timesheet ON emp.empid = timesheet.empid WHERE emp.empid IN ($emplist) ORDER BY emp.empid, timesheet.date_workd"; $res = $db->query($sql); echo '<pre>'; while ($row = $res->fetch_row()) { vprintf("%2d %-15s %-12s %3d\n", $row); } echo '</pre>'; Giving, for Area Mgr 2 : 3 Area Mgr 2 2013-05-24 3 3 Area Mgr 2 2013-05-25 7 6 Team Ldr 2A 2013-05-24 3 6 Team Ldr 2A 2013-05-25 7 7 Team Ldr 2B 2013-05-24 3 7 Team Ldr 2B 2013-05-25 7 12 Emp 2A1 2013-05-24 3 12 Emp 2A1 2013-05-25 7 13 Emp 2A2 2013-05-24 3 13 Emp 2A2 2013-05-25 7 14 Emp 2B1 2013-05-24 3 14 Emp 2B1 2013-05-25 7 15 Emp 2B2 2013-05-24 3 15 Emp 2B2 2013-05-25 7
  16. BETWEEN '$datefrom' - 60 AND '$datefrom' - 31 should be BETWEEN '$datefrom' - INTERVAL 60 DAY AND '$datefrom' - INTERVAL 31 DAY and alter others accordingly. (Assuming your dates are held as type DATE and you are using yyyy-mm-dd for input date too)
  17. my earlier reply #7 showed you how to handle it in mysql and PHP
  18. The mysql ORDER BY works fine for me mysql> SELECT thedate, -> DATE_FORMAT(thedate, '%M %e, %Y') as formatted -> FROM test.dates -> WHERE thedate < '2012-01-05' -> ORDER BY MONTH(thedate), DAY(thedate) DESC; +------------+-------------------+ | thedate | formatted | +------------+-------------------+ | 2012-01-04 | January 4, 2012 | | 2012-01-03 | January 3, 2012 | | 2012-01-02 | January 2, 2012 | | 2012-01-01 | January 1, 2012 | | 1893-02-21 | February 21, 1893 | +------------+-------------------+
  19. Do you see the button labelled "Mark Solved"?
  20. strict or just plain sloppy?
  21. SELECT thedate, DATE_FORMAT(thedate, '%M %e, %Y') FROM test.dates ORDER BY thedate LIMIT 2; +------------+-----------------------------------+ | thedate | DATE_FORMAT(thedate, '%M %e, %Y') | +------------+-----------------------------------+ | 1893-02-21 | February 21, 1893 | | 2012-01-01 | January 1, 2012 | +------------+-----------------------------------+ Alternatively, $d = new DateTime('1893-02-21'); echo $d->format('F j, Y'); //-> February 21, 1893
  22. If you want to compare dates and times then store them in a format that can be compared ie yyyy-mm-dd hh:ii:ss
  23. You don't need 3 update queries, 1 will do. Syntax is UPDATE tablename SET a = x, b = y, c = z WHERE whatever = something
  24. What we, and you, need to see is the result of echo $sql_auction; so we can see exactly what is being executed
  25. column names do not have quotes
×
×
  • 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.