-
Posts
24,573 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
Having font size troubles with imagettftext
Barand replied to BlackDragonIV's topic in PHP Coding Help
-
Looks like your widget is json encoding the form data - you'll need to decode it to process the contents $pet_data = json_decode($_POST['petlist']['petlist'], true); which should give you ann array like this $pet_data = Array ( [0] => Array ( [Pet Name] => Hal [Pet Type] => Dog [Breed] => Lab [DOB] => 02/10/2013 [Gender] => Male [Special Needs] => No ) [1] => Array ( [Pet Name] => Bill [Pet Type] => Dog [Breed] => Golden [DOB] => 03/20/2015 [Gender] => Male [Special Needs] => No ) ) You will need to reformat your dates before putting into your table (store as yyyy-mm-dd). Why are you adding slashes to all your data? Use prepared queries with mysqli or PDO (preferred). The mysql_ library you are using is obsolete. Why checkboxes for pet type? No one has a pet that is both cat and dog!. Your data column types are overkill. You'll find it more efficient to use INSERT … ON DUPLICATE KEY UPDATE... than your method of checking if it exists then inserting or updating.
-
Having font size troubles with imagettftext
Barand replied to BlackDragonIV's topic in PHP Coding Help
On the whole the dimensions returned by imagettfbbox() are pretty accurate. In the image below, the rectangles and baseline position are the dimensions returned by imagettfbbox(). The text then output into the box at the baseline position to check. ("Broadway" font is a couple of pixels out but the rest are spot on) Note that all coordinates returned for the bbox are integers. The code used: -
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.
-
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?
-
Having font size troubles with imagettftext
Barand replied to BlackDragonIV's topic in PHP Coding Help
Don't know what you're trying to produce but have you considered SVG instead of bitmapped graphics? They rescale better. -
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.
-
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.
-
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.
-
Presumably he posted legible, well formatted code in that one. Thanks for the heads up.
-
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.
-
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 | +------------+---------+
-
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 | +------------+---------+
-
(PHP) Need to change currency function to percentual (%) (at one line)
Barand replied to Netchain's topic in PHP Coding Help
Have you tried echo $change . '%'; -
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?) +------+------+------+------+
-
(PHP) Need to change currency function to percentual (%) (at one line)
Barand replied to Netchain's topic in PHP Coding Help
percent = (amount_changed / yesterdays_closing_price) * 100 -
$price = 278.53; $cents = $price * 100; $end_result = $cents ; // without the (int) gives 27853
-
foreach ($data as $k => $v) { if (is_object($v)) { foreach ($v as $k1 => $v1) { echo "$k1 : $v1 <br>"; } } }
-
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>'; } }
-
Getting the error Undefined index but the column exists
Barand replied to makamo66's topic in PHP Coding Help
So you are one of those people who likes to waste people's time by posting simultaneously on multiple forums? That will be remembered. -
Getting the error Undefined index but the column exists
Barand replied to makamo66's topic in PHP Coding Help
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. -
Isn't that just another category (I.E. Free)?
-
Other than filtering by category, how is this different from your last topic?
-
Getting the error Undefined index but the column exists
Barand replied to makamo66's topic in PHP Coding Help
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' ");