Jump to content

Barand

Moderators
  • Posts

    24,615
  • Joined

  • Last visited

  • Days Won

    835

Everything posted by Barand

  1. You can have only one else per if. You can have several elseif's though
  2. The problem is here (obvious when you look at the colour formatting of the posted code) $saveDir = "c:\wamp64\www\script\images\"; ^ "\"s are escape characters, so the final one escapes the ending ". You need to use \\ or / as path separators.
  3. You don't need a separate query to get the column names. If your fetch() returns an associative array, the keys are the column names. $res = $db->query("SELECT * FROM lu_phase"); $row = $db->fetch(PDO::FETCH_ASSOC); echo "<table>"; echo "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>"; do { echo "<tr><td>" . join('</td><td>', $row) . '</td></th>'; } while ($row = $db->fetch(PDO::FETCH_ASSOC)); echo "</table>";
  4. Use $diff->days. $dt1 = new DateTime('2020-05-01'); $diff = $dt1->diff(new DateTime())->d; //--> 14; $diff = $dt1->diff(new DateTime())->days; //--> 44; ->d gives the days as in "1 month 14 days" ->days gives the total days Using SQL: select datediff(curdate(), '2020-05-01') as days; +------+ | days | +------+ | 44 | +------+
  5. Try changing echo json_encode($data); to exit(json_encode($data));
  6. Have you checked what is being passed to and from the ajax call in your browsers developer tools?
  7. Put the variable value into a hidden field in the html. In the JS, get the value from the hidden field.
  8. foreach ($global_array as $k => $v) { foreach ($global_array as $k1 => $v1) { if ($k==$k1) continue; if (array_values(array_intersect($v, $v1)) == array_values($v1)) { unset($global_array[$k1]); } } }
  9. I don't see any subarrays in that array of yours that would be a candidate for removal - no duplicates edit: ignore me - I misunderstood the problem. "contained in" and not "equal"
  10. Why store the excerpt? You can just select the first 100 chars of the content when you want to display an excerpt. $sql = "SELECT b.id , b.title , c.name AS category , b.tags , content , LEFT(content, 100) as excerpt , photo , b.date AS pubDate , 'Jennifer' AS author FROM blogs AS b JOIN blog_categories c ON b.category=c.id WHERE posted = 'publish' ORDER BY DATE DESC LIMIT 2 ";
  11. If you are looking for words that are common to both $abs and $mT <?php $abs="one two three four words"; $mT = "testing for matching words"; $absArr = explode(' ', $abs); $mTArr = explode(' ', $mT); $common = array_intersect($absArr, $mTArr); // check result echo '<pre>', print_r($common, 1), '</pre>'; ?>
  12. You are setting the option values to $row['member'] but you don't select anything called "member" Why concatenate nothing at the end of the line? Why are you processing the posted data in the middle of your form output? Move it before the form. The $id in the form is doing nothing. Other problems you have already been told about and done nothing to fix them.
  13. Let's narrow it down further ?schoolname={$school_page}?action=add
  14. therefore someone else in another forum had their time wasted too.
  15. For the record, with PDO I get the types with query() and prepare() (although, as expected, dates are "string") $res = $db->query("select id , date , opposition , attendance from seasonstats limit 1"); $r = $res->fetch(); echo '<pre> query result <br>'; var_dump($r); $res = $db->prepare("select id , date , opposition , attendance from seasonstats limit 1"); $res->execute(); $r = $res->fetch(); echo '<pre> prepare result <br>'; var_dump($r); Results query result array(4) { ["id"]=> int(1) ["date"]=> string(10) "2010-08-07" ["opposition"]=> string(14) "Crystal Palace" ["attendance"]=> int(17486) } prepare result array(4) { ["id"]=> int(1) ["date"]=> string(10) "2010-08-07" ["opposition"]=> string(14) "Crystal Palace" ["attendance"]=> int(17486) }
  16. It had occurred to me that an alternative approach to the problem might be on the cards, but without knowing what you were starting with there wasn't much anyone else could do. Hence the request for the input tables.
  17. OK, if you're happy to continue coding your queries like that, I'll leave you to it.
  18. There has to be a more efficient way of achieving your goal. Running queries inside loops like that is not the best way. What are the structures of the tables you are querying (the two in that query and the one for the outer query)?
  19. What code do you have so far?
  20. If you don't want to take our advice, you could resort to SELECT h1.emp_id , h1.pay , h1.hours1 , h2.hours2 , h3.hours3; SELECT * FROM ( SELECT e.emp_id , e.pay , ot.hours1 as hours FROM employeex e JOIN employeex e2 ON e.time1 = e2.emp_id JOIN overtimex ot ON e2.grade = ot.rank ) h1 JOIN ( SELECT e.emp_id , e.pay , ot.hours2 FROM employeex e JOIN employeex e2 ON e.time2 = e2.emp_id JOIN overtimex ot ON e2.grade = ot.rank ) h2 ON h1.emp_id = h2.emp_id JOIN ( SELECT e.emp_id , e.pay , ot.hours3 FROM employeex e JOIN employeex e2 ON e.time3 = e2.emp_id JOIN overtimex ot ON e2.grade = ot.rank ) h3 ON h1.emp_id = h3.emp_id WHERE h1.emp_id = 67;
  21. In a very to similar manner to the code already given. SELECT name , 'Y' as paid FROM fee WHERE month(month) IN (3,4,5) AND paid = 'Y' GROUP BY name HAVING count(*) = 3;
  22. Still don't know what chat message data or production data you have. All I see are four chat_message_to records. Nor do I know what results you are expecting.
  23. It doesn't look like your query contains the name of the commenter in its results. Could that be the problem?
  24. Ah yes , the three types of programmer, those who can count and those who can't Use a table subquery to find those who paid all two and match against it with a join SELECT name , month(month) as mno , paid FROM fee JOIN ( SELECT name , count(*) FROM fee WHERE month(month) IN (3,4,5) AND paid = 'Y' GROUP BY name HAVING count(*) = 3 ) paid3 USING (name) WHERE month >= '2020-03-01' ORDER BY name, month
  25. Or just use Excel instead of trying to store spreadsheet tables in a database. I agree with @benanamen - normalize. Something like this +------------+ | employee | +------------+ +------------+ | emp_id |----+ | time | | fname | | +------------+ | lname | | | time_no |----+ | pay | +----<| emp_id | | | grade |--+ | time_emp | | +------------+ | +------------+ | | | | +------------+ | | | overtime | | | +------------+ | +------<| grade | | | time_no |>---+ | hours | +------------+ Your table data employee time overtime +--------+-------+-------+ +---------+--------+----------+ +-------+-------+---------+-------+ | emp_id | pay | grade | | time_no | emp_id | time_emp | | ot_id | grade | time_no | hours | +--------+-------+-------+ +---------+--------+----------+ +-------+-------+---------+-------+ | 11 | 12500 | 3 | | 1 | 11 | 6 | | 1 | 3 | 1 | 10 | | 15 | 15000 | 5 | | 1 | 15 | 4 | | 2 | 3 | 2 | 5 | | 23 | 17000 | 7 | | 1 | 23 | 15 | | 3 | 3 | 3 | 0 | | 67 | 20000 | 9 | | 1 | 67 | 23 | | 4 | 5 | 1 | 15 | +--------+-------+-------+ | 2 | 11 | 2 | | 5 | 5 | 2 | 10 | | 2 | 15 | 23 | | 6 | 5 | 3 | 5 | | 2 | 23 | 8 | | 7 | 7 | 1 | 20 | | 2 | 67 | 15 | | 8 | 7 | 2 | 15 | | 3 | 11 | 19 | | 9 | 7 | 3 | 10 | | 3 | 15 | 10 | | 10 | 9 | 1 | 25 | | 3 | 23 | 11 | | 11 | 9 | 2 | 20 | | 3 | 67 | 11 | | 12 | 9 | 3 | 15 | +---------+--------+----------+ +-------+-------+---------+-------+ Then SELECT e.emp_id , e.pay , t.time_no , ot.hours FROM employee e JOIN time t ON e.emp_id = t.emp_id JOIN employee e2 ON t.time_emp = e2.emp_id JOIN overtime ot ON e2.grade = ot.grade AND t.time_no = ot.time_no WHERE e.emp_id = 67 ORDER BY time_no; +--------+-------+---------+-------+ | emp_id | pay | time_no | hours | +--------+-------+---------+-------+ | 67 | 20000 | 1 | 20 | | 67 | 20000 | 2 | 10 | | 67 | 20000 | 3 | 0 | +--------+-------+---------+-------+
×
×
  • 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.