-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Don't use 2 queries when 1 will do SELECT c.id , c.name , c.last_name , c.mobile_number , c.status , a.username as mentorname FROM contacts c LEFT JOIN accounts a ON c.mentor = a.id WHERE c.id = 1; +----+-------+-----------+---------------+---------+------------+ | id | name | last_name | mobile_number | status | mentorname | +----+-------+-----------+---------------+---------+------------+ | 1 | Scott | Chegg | 01012345678 | current | jbloggs | +----+-------+-----------+---------------+---------+------------+
-
I see you joined in 2003 - experience is always welcome.
-
How to process the multi dimensional array into specific array?
Barand replied to soyaslim's topic in PHP Coding Help
It's the append that makes the difference. Your solution was always overwriting the product id that that was there. -
How to process the multi dimensional array into specific array?
Barand replied to soyaslim's topic in PHP Coding Help
All you need to do is loop through your original array using foreach() and append the products to a new array, providing the required key values. foreach ($orig as $rec) $new[ $rec['supplier'] ]['productID'][] = $rec['part_id']; Result for $new Array ( [COOLDRIVE DISTRIBUTION] => Array ( [productID] => Array ( [0] => 2338117 ) ) [ROLAN] => Array ( [productID] => Array ( [0] => 2338117 [1] => 51154 ) ) ) -
How to process the multi dimensional array into specific array?
Barand replied to soyaslim's topic in PHP Coding Help
What have you tried so far? -
Need this code to demote user role if points fall below minimum
Barand replied to Cybercli's topic in PHP Coding Help
PS If you really want to do it in PHP then you can apply the same method to an array $thresholds = array( '-' => [0, 100], 'contributor' => [101, 1000], 'author' => [1001, 10000], 'editor' => [10001, 100000], 'administrator' => [100001, 999999999] ); echo getUserRole(50000, $thresholds); //--> editor function getUserRole($current_balance, $thresholds) { foreach ( $thresholds as $role => $range ) { if ( $range[0] <= $current_balance && $current_balance <= $range[1] ) { return $role; } } return false; } -
Need this code to demote user role if points fall below minimum
Barand replied to Cybercli's topic in PHP Coding Help
With a couple of db tables like this Table: user Table: role +---------+----------+--------+ +---------+---------------+-----------+------------+ | user_id | username | points | | role_id | role_name | point_min | points_max | +---------+----------+--------+ +---------+---------------+-----------+------------+ | 1 | John | 66 | | 5 | - | 0 | 100 | | 2 | Paul | 101 | | 6 | Contributor | 101 | 1000 | | 3 | George | 3000 | | 7 | Author | 1001 | 10000 | | 4 | Ringo | 200000 | | 8 | Editor | 10001 | 100000 | +---------+----------+--------+ | 9 | Administrator | 100001 | 999999999 | +---------+---------------+-----------+------------+ Then a simple query SELECT username , rolename FROM user u JOIN role r ON u.points BETWEEN r.points_min AND r.points_max; does the job for you +----------+---------------+ | username | rolename | +----------+---------------+ | John | - | | Paul | Contributor | | George | Author | | Ringo | Administrator | +----------+---------------+ -
How to generate multiple image from single template using php
Barand replied to neilfurry's topic in PHP Coding Help
That's because you keep writing to the same image template. Recreate each time in the loop and destroy at the end to release the memory. $sql = mysqli_query($con, "SELECT id, empname FROM employees"); header('Content-type: image/png'); $image = imagecreatefrompng('id-template.png'); $color = imagecolorallocate($image, 0, 0, 0); imagepng($image); while($rs = mysqli_fetch_assoc($sql)){ $image = imagecreatefrompng('id-template.png'); $color = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 13, 0, 60,117, $color, $font, $rs['empname']); //employee name location of the template $save = "id/".strtolower($rs['id']).".png"; imagepng($image, $save, 9, PNG_NO_FILTER); imagedestroy($image) } PS Wouln't it make more sense to have a different image for each employee - or do you only employ clones? -
Warning tells me that Count () needs to be an array
Barand replied to nextgen's topic in PHP Coding Help
Then $_POST['nfield'] is not an array as exepected. You need to check why. What is the form markup code where it originates? -
My question... His answer... Apparently he thinks error messages are just unnecessary clutter to be ignored.
-
Apparently they were for you too when you woke up... What changed? Did you then read the error messages?
-
Perhaps reading the error messages might give you a clue, even if the errors are glaringly obvious. At least you are able to read them; an opportunity not given to anyone else.
-
perhaps ? echo str_replace("\\", "\\u{", "\\f192"); //--> \u{f192
-
Change it. E_ALL and E_NOTICE = E_NOTICE | E_ALL | 111111111111111 | | E_NOTICE | 1000 | | E_ALL & E_NOTICE | 1000 | If you want to switch off notices you need E_ALL and not E_NOTICE | E_ALL &~ E_NOTICE | 111111111110111 | (By the time you get to production any e_notices should've been eliminated)
-
-> +-----------------------+---------------+--------------+ | php.ini file setting | development | production | | | server | server | +-----------------------+---------------+--------------+ | error_reporting | E_ALL | E_ALL | | display_errors | ON | OFF | | log_errors | OFF | ON | +-----------------------+---------------+--------------+
-
Then remove it. I put it there to make it easy for me to check that the data differences were correct. When you come across an example of how to do something then you have to adapt that example to your situation and needs - not blindly copy, paste and pray.
-
All you needed to do was substitute your connection "$conn" for my "$pdo". My coding in this instance is mysqli/pdo neutral. Remove the catch{} stuff.
-
Perhaps he hasn't realized yet that ignoring your commandments can cause your wrath to descend on him in the form of seven deadly plagues.
-
He is saying that to output a "%" in a format string you need to have "%%". printf("<img src='images/%s' style='width: 100%%' />" , basename($filename));
-
Because you don't have database connection in a variable $pdo. That depends on what you do with them.
-
Or do it the easy way code $res = $pdo->query("SELECT created_at FROM test_b ORDER BY created_at DESC "); $today = new DateTime('now'); foreach ($res as $row) { $dt = new DateTime($row['created_at']); $diff = $dt->diff($today)->format("%y years -- %m months -- %d days"); echo "{$row['created_at']} | $diff <br>"; } output 2020-10-15 00:00:00 | 1 years -- 9 months -- 22 days 2020-09-06 00:00:00 | 1 years -- 11 months -- 0 days 2019-04-09 00:00:00 | 3 years -- 3 months -- 28 days 2019-03-08 00:00:00 | 3 years -- 4 months -- 29 days 2018-06-06 00:00:00 | 4 years -- 2 months -- 0 days 2018-06-04 00:00:00 | 4 years -- 2 months -- 2 days 2018-05-27 00:00:00 | 4 years -- 2 months -- 10 days 2018-05-15 00:00:00 | 4 years -- 2 months -- 22 days 2018-02-03 00:00:00 | 4 years -- 6 months -- 3 days 2018-01-05 00:00:00 | 4 years -- 7 months -- 1 days
-
How can I pass class object to onclick function ?
Barand replied to eaglehopes's topic in Javascript Help
I am curious - what was the original problem for which you have the above as a solution? -
PHP isn't targeting guest customers in Woocommerce
Barand replied to martini0's topic in PHP Coding Help