-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Efficiency. One table subquery called once versus a dependent subquery called for every row
-
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
-
try a JOIN Select artist from songlist inner join (Select distinct title from songlist where artist='Bob Dylan') as dylan using (title)
-
What format / column type is post_time_dif?
-
Is there a better way to write this php / mysql script?
Barand replied to Stuart_Westgate's topic in PHP Coding Help
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? -
if(STORE_MIN_DELIVERY !=0 && STORE_MIN_DELIVERY !=NULL )
-
$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.
-
How do I add to an associate array to a associate array?
Barand replied to Stuart_Westgate's topic in PHP Coding Help
If I understand while ($row = mysqli_fetch_assoc($result) { $media[$row['id']] = $row; } -
$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;
-
I gave him the query, can't understand what there is left to be stuck on
-
that gives highest first
-
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.
-
SELECT name, COUNT(*) as tot FROM table GROUP BY name ORDER BY tot LIMIT 1
-
What format are your dates?
-
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
-
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)
-
my earlier reply #7 showed you how to handle it in mysql and PHP
-
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 | +------------+-------------------+
-
Do you see the button labelled "Mark Solved"?
-
strict or just plain sloppy?
-
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
-
What we, and you, need to see is the result of echo $sql_auction; so we can see exactly what is being executed
-
column names do not have quotes