Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. 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 | +----+-------+-----------+---------------+---------+------------+
  2. Barand

    Hello!!!

    I see you joined in 2003 - experience is always welcome.
  3. It's the append that makes the difference. Your solution was always overwriting the product id that that was there.
  4. 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 ) ) )
  5. 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; }
  6. 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 | +----------+---------------+
  7. 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?
  8. Then $_POST['nfield'] is not an array as exepected. You need to check why. What is the form markup code where it originates?
  9. My question... His answer... Apparently he thinks error messages are just unnecessary clutter to be ignored.
  10. Apparently they were for you too when you woke up... What changed? Did you then read the error messages?
  11. 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.
  12. perhaps ? echo str_replace("\\", "\\u{", "\\f192"); //--> \u{f192
  13. 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)
  14. -> +-----------------------+---------------+--------------+ | php.ini file setting | development | production | | | server | server | +-----------------------+---------------+--------------+ | error_reporting | E_ALL | E_ALL | | display_errors | ON | OFF | | log_errors | OFF | ON | +-----------------------+---------------+--------------+
  15. Barand

    Howdy!

    Welcome
  16. 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.
  17. 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.
  18. 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.
  19. 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));
  20. Because you don't have database connection in a variable $pdo. That depends on what you do with them.
  21. 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
  22. I am curious - what was the original problem for which you have the above as a solution?
×
×
  • 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.