Jump to content

Barand

Moderators
  • Posts

    24,344
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. According to your logon code, if the username and password are ok then $_SESSION['login_user'] = $username; // Initializing Session so why are you testing $_SESSION['username'] for 0 or 1.
  2. Set those in your php.ini file, not in the code. If you have any startup errors the code won't execute. If it won't execute it can't set those values. Try changing that to if(!isset($_SESSION['username'] || $_SESSION['username'] =="")){ // To check if the user has logged in Have you checked that the session value is being set on login?
  3. Don't know what you're trying to produce but have you considered SVG instead of bitmapped graphics? They rescale better.
  4. There seems to be some discrepancy with exactly what session variable to check. You need to exit after a redirect to prevent the rest of the code from executing EG In that first line above. Your main problem is trying to use mysql_ functions with v7.0+ (they no longer exist). Had you not turned off the error reporting with error_reporting(0) it might have told you. Use mysqli_ or PDO (better than mysqli). Use prepared queries instead of putting user data directly into the query to prevent SQL injection.
  5. If you want people to look at your code then format it so it is clear, by virtue of its indentations, where your various control blocks start and end. (BTW, our first if() {…} block has no end) Put your code in a code block, either with code tags or use the <> button in the toolbar.
  6. Your time might have been better spent reading on the first night and fixing on the second. Sounds like you want us to do it for you rather than give help.
  7. Presumably he posted legible, well formatted code in that one. Thanks for the heads up.
  8. Then you definitely need a left join. Without it, if there is no data, there is no row. Consider a teacher taking the morning attendance roll call. There are two way they can do it use a register of all the names and check off each child present request that anyone not present raise their hand The former method is the LEFT JOIN approach; the latter method is what you are attempting which suggests that the 'enne' condition should also be in the join's ON clause... SELECT d.date , CASE WHEN enne IS NULL THEN 'NO DATA' ELSE SUM(score > 2) END as head FROM ( SELECT DISTINCT date FROM kilnakorr ) d LEFT JOIN kilnakorr k ON d.date = k.date AND enne = 'ennehead' AND user='fred' AND department='sales' GROUP BY d.date; EDIT: Note that creating the data table using a subquery assumes that there will be at least one record for every date for someone. If this is not the case then you need to generate a (temporary) date table containing all the dates you need to appear, as in my earlier example.
  9. Then we'll use sql magic to conjure the date table with a subquery SELECT d.date , CASE WHEN enne IS NULL THEN 'NO DATA' ELSE SUM(CASE WHEN `enne`='ennehead' AND score>2 THEN 1 ELSE 0 END) END as head FROM ( SELECT DISTINCT date FROM kilnakorr ) d LEFT JOIN kilnakorr k ON d.date = k.date AND user='hercules' AND department='sales' GROUP BY d.Date; +------------+---------+ | date | head | +------------+---------+ | 2019-10-01 | NO DATA | | 2019-10-02 | NO DATA | | 2019-10-03 | NO DATA | +------------+---------+
  10. OK, my final guess at you scenario INPUT... TABLE: kilnakorr_date TABLE: kilnakorr +------------+ +----+----------+------------+-------+-------+------------+ | date | | id | enne | date | score | user | department | +------------+ +----+----------+------------+-------+-------+------------+ | 2019-10-01 | | 13 | ennehead | 2019-10-01 | 1 | fred | sales | | 2019-10-02 |-----------+ | 14 | ennehead | 2019-10-01 | 3 | fred | sales | | 2019-10-03 | | | 15 | ennehead | 2019-10-01 | 5 | fred | sales | +------------+ | | 16 | head | 2019-10-01 | 1 | fred | sales | | | 17 | ennehead | 2019-10-01 | 3 | curly | accts | +------------0<| 18 | ennehead | 2019-10-01 | 5 | mo | accts | | 19 | ennehead | 2019-10-02 | 1 | fred | sales | | 20 | ennehead | 2019-10-02 | 3 | pete | sales | | 21 | ennehead | 2019-10-02 | 5 | mary | sales | | 22 | head | 2019-10-02 | 1 | fred | sales | | 23 | ennehead | 2019-10-02 | 3 | curly | accts | | 24 | ennehead | 2019-10-02 | 5 | mo | accts | +----+----------+------------+-------+-------+------------+ Then... SELECT d.date , CASE WHEN enne IS NULL THEN 'NO DATA' ELSE SUM(CASE WHEN `enne`='ennehead' AND score>2 AND user='fred' THEN 1 ELSE 0 END) END as head FROM kilnakorr_date d LEFT JOIN kilnakorr k ON d.date = k.date AND score>2 AND department='sales' GROUP BY d.Date; +------------+---------+ | date | head | +------------+---------+ | 2019-10-01 | 2 | | 2019-10-02 | 0 | | 2019-10-03 | NO DATA | +------------+---------+
  11. Not sure I totally understand. If you had this situation below, what output would you want to see? SELECT * FROM kilnakorr; +----+------+------+------+------+ | id | cola | colb | colc | cold | +----+------+------+------+------+ | 1 | bar | foo | bar | NULL | | 2 | foo | foo | NULL | NULL | | 3 | foo | foo | bar | NULL | | 4 | bar | foo | NULL | NULL | +----+------+------+------+------+ SELECT SUM(CASE WHEN cola = 'bar' THEN 1 ELSE 0 END) as tota , SUM(CASE WHEN colb = 'bar' THEN 1 ELSE 0 END) as totb , SUM(CASE WHEN colc = 'bar' THEN 1 ELSE 0 END) as totc , SUM(CASE WHEN cold = 'bar' THEN 1 ELSE 0 END) as totd FROM kilnakorr; +------+------+------+------+ | tota | totb | totc | totd | +------+------+------+------+ | 2 | 0 | 2 | 0 | (What do you want to see here?) +------+------+------+------+
  12. $price = 278.53; $cents = $price * 100; $end_result = $cents ; // without the (int) gives 27853
  13. foreach ($data as $k => $v) { if (is_object($v)) { foreach ($v as $k1 => $v1) { echo "$k1 : $v1 <br>"; } } }
  14. That "array" is an object. (if it came from json data, decode it as an array instead of an object) $a = json_decode(json_encode($data), true); // convert the object to an array foreach ($a as $k => $v) { if (is_array($v)) { echo $v['orders.orderid'] . '<br>'; } }
  15. So you are one of those people who likes to waste people's time by posting simultaneously on multiple forums? That will be remembered.
  16. Your error is because you have no parameter placeholders in the query that you are preparing. (See the examples) Dates stored in that format are as much use as a chocolate teapot. You cannot do correct comparisons and therefore you can't sort them. You can't use the dozens of date/time functions without reformatting Store data for functionality, not prettiness. You can format it for human consumption on output, I've told you the correct format to use.
  17. The best thing is to remove those three SELECT … statements at line 29. They don't accomplish anything. You cannot just put raw SQL into the middle of a php script.
  18. Isn't that just another category (I.E. Free)?
  19. Other than filtering by category, how is this different from your last topic?
  20. I see no problem with this (eg if date comes from a date picker) as the date finally used is not that originally input... $date = (new DateTime($_POST['date']))->format('Y-m-d'); $res = $pdo->query("SELECT whatever FROM tablename WHERE thedate > '$date' ");
  21. String literals in a query require single quotes otherwise they are treated as column names. Identifiers which contain spaces, or are reserved words, require backticks. SELECT `group` , fname as `first name` FROM user WHERE lname = 'jones' ;
  22. DATETIME columns require Y-m-d H:i:s format. (eg 2019-10-23 14:52:38 ) Have you checked the column exists, say, with "DESCRIBE comment_table" or "SHOW CREATE TABLE comment_table"? @gw1500se the quotes are correct mysqli_query($connection, "INSERT INTO comment_table (name, date_col) VALUES ('$name', '$date_col')"); ^ ^
×
×
  • 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.