Jump to content

Barand

Moderators
  • Posts

    24,572
  • Joined

  • Last visited

  • Days Won

    824

Everything posted by Barand

  1. I was unable to re-create the error. It all seems to work fine for me. The only problem I can see is you are outputting an unnecessary linefeed at the end. echo '<center dir="ltr">'.$Number.' new number saved</center>'; fwrite($file_D,"\n"); // <-------- not required fclose($file_S); fclose($file_D);
  2. Does mysql_error() say you have a syntax error?
  3. Backup your data first DELETE profile FROM profile JOIN ( SELECT street FROM profile GROUP BY street HAVING COUNT(*) > 1 ) as dupes USING (street) WHERE status = 'Unknown'
  4. Sphinx supports InnoDB
  5. Even though you are not calling mysql_close() the connection will close automatically at end of each page script. Connect once at beginning of each page that requires mysql
  6. WHERE name LIKE '%$word1%' AND name LIKE '%$word2%' AND name LIKE '%$word3%'
  7. Have a look at MySQL FULLTEXT searches
  8. If you want to constrain $maindamage to a minimum value of 10 $maindamage = max(10, ($rpgdata['max_dmg'] / $rpgdata['min_dmg']));
  9. Efficiency. One table subquery called once versus a dependent subquery called for every row
  10. 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
  11. try a JOIN Select artist from songlist inner join (Select distinct title from songlist where artist='Bob Dylan') as dylan using (title)
  12. What format / column type is post_time_dif?
  13. 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?
  14. if(STORE_MIN_DELIVERY !=0 && STORE_MIN_DELIVERY !=NULL )
  15. $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.
  16. If I understand while ($row = mysqli_fetch_assoc($result) { $media[$row['id']] = $row; }
  17. $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;
  18. I gave him the query, can't understand what there is left to be stuck on
  19. that gives highest first
  20. 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.
  21. SELECT name, COUNT(*) as tot FROM table GROUP BY name ORDER BY tot LIMIT 1
  22. What format are your dates?
  23. 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
  24. 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)
×
×
  • 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.