Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Barand

    Cookie DB

    Which field/s determine if a cookie exists or not? I would guess at domain/name
  2. Sort into descending order Get the second element.
  3. Barand

    Cookie DB

    You are doing it backwards. You need to insert but if it does exist then update instead. INSERT INTO tablename ( ... ) VALUES (...) ON DUPLICATE KEY UPDATE .... https://dev.mysql.com/doc/refman/5.7/en/insert.html
  4. if () is the construct that springs to mind.
  5. phpinfo() will tell you which folder is defined (in php.ini file) as your extensions folder. You will find it in the "Core" section of the output. That is where your extension files need to be.
  6. I find it comforting to know that it will try.
  7. As well as checking your database default encoding is UTF8 you need to check that the tables and problematic fields are using the default (as the charsets can be overridden at each level). Your HTML also needs to be defined with charset UTF-8. In addition, the db connection (the bridge between the two) also needs the charset defining as UTF8.
  8. Forget the above. I have now realized that I completely missed that your module_access on had links to the 2 parent modules. Here's an alternative approach $uID = 1; $res = $con->prepare("SELECT m1.mod_name as name1 , m2.mod_name as name2 , m2.link as link2 FROM module m1 JOIN module m2 ON m1.mid = m2.parent_id JOIN module_access ma ON (m1.mid = ma.page_id) WHERE ma.user=? ORDER BY m1.mid "); $res->execute([$uID]); $mods = []; foreach ($res as $row) { if (!isset($mods[$row['name1']])) { $mods[$row['name1']] = []; } $mods[$row['name1']][$row['name2']] = $row['link2'] ; } The mods array now contains... Array ( [Sales] => Array ( [Quotes] => quotes.php [Clients] => clients.php ) [Finance] => Array ( [Invoices] => invoices.php [Expense] => expenses.php [Taxes] => taxes.php ) ) ... which you can loop through to give the output function showMenu(&$arr) { echo "<ul>\n"; foreach($arr as $parent => $modules) { echo "<li class='li0'>$parent\n"; echo "<ul>\n"; foreach ($modules as $name => $link) { echo "<li class='li1'><a href='$link'>$name</a>\n"; } echo "</ul>\n"; echo "</li>\n"; } echo "</ul>\n"; } giving
  9. The data you posted: mysql> select * from module; +-----+----------+-----------+--------------+ | mid | mod_name | parent_id | link | +-----+----------+-----------+--------------+ | 1 | Sales | 0 | # | | 2 | Purchase | 0 | # | | 3 | Finance | 0 | # | | 4 | Clients | 1 | clients.php | | 5 | Quotes | 1 | quotes.php | | 6 | Vendors | 2 | vendors.php | | 7 | POs | 2 | pos.php | | 8 | Invoices | 3 | invoices.php | | 9 | Taxes | 3 | taxes.php | | 10 | Expense | 3 | expenses.php | +-----+----------+-----------+--------------+ mysql> select * from module_access; +----+---------+------+ | id | page_id | user | +----+---------+------+ | 1 | 1 | 1 | | 2 | 3 | 1 | | 3 | 4 | 1 | | 4 | 9 | 1 | | 5 | 10 | 1 | +----+---------+------+ Your revised query gives me mysql> SELECT mid -> , mod_name -> , parent_id -> , link -> FROM module m -> JOIN module_access ma ON (m.mid=ma.page_id OR ma.page_id=m.parent_id) -> WHERE ma.user=1 -> ORDER BY m.mid; +-----+----------+-----------+--------------+ | mid | mod_name | parent_id | link | +-----+----------+-----------+--------------+ | 1 | Sales | 0 | # | | 3 | Finance | 0 | # | | 4 | Clients | 1 | clients.php | | 4 | Clients | 1 | clients.php | | 5 | Quotes | 1 | quotes.php | | 8 | Invoices | 3 | invoices.php | | 9 | Taxes | 3 | taxes.php | | 9 | Taxes | 3 | taxes.php | | 10 | Expense | 3 | expenses.php | | 10 | Expense | 3 | expenses.php | +-----+----------+-----------+--------------+ and the script now outputs... I can only assume that your data is not what you posted. [edit] Perhaps you have a varchar instead of int that contains hidden whitespace so they are not matching in the joins? What do these two queies output?... SELECT id , page_id , HEX(page_id) , user , HEX(user) FROM module_access; SELECT mid , HEX(mid) , parent_id , HEX(parent_id) FROM module;
  10. Wierd!. Whether I run my code or your above code (modified only to use table name "module" to match my DB) I get exactly the same output ... The generated HTML being ... <ul> <li class="li0"><a href="#"> Sales </a> <ul> <li class="li1"><a href="clients.php"> Clients </a> </li> </ul> </li> <li class="li0"><a href="#"> Finance </a> <ul> <li class="li1"><a href="taxes.php"> Taxes </a> </li> <li class="li1"><a href="expenses.php"> Expense </a> </li> </ul> </li> </ul> What does your query return? mysql> SELECT mid -> , mod_name -> , link -> , parent_id -> FROM module m -> JOIN module_access ma ON m.mid = ma.page_id -> WHERE ma.user = 1; +-----+----------+--------------+-----------+ | mid | mod_name | link | parent_id | +-----+----------+--------------+-----------+ | 1 | Sales | # | 0 | | 3 | Finance | # | 0 | | 4 | Clients | clients.php | 1 | | 9 | Taxes | taxes.php | 3 | | 10 | Expense | expenses.php | 3 | +-----+----------+--------------+-----------+
  11. Something like this <?php require 'db_inc.php' $uid = 1; $stmt = $con->prepare("SELECT mid , mod_name , link , parent_id FROM module m JOIN module_access ma ON m.mid = ma.page_id WHERE ma.user = ?; "); $stmt->execute( [$uid] ); $mods = []; foreach ($stmt as $row) { $mods[$row['parent_id']][] = $row; } function showMenu(&$arr, $parent = 0, $level = 0) { if (!isset($arr[$parent])) return; echo "<ul>\n"; foreach($arr[$parent] as $rec) { echo "<li class='li$level'><a href='{$rec['link']}'> {$rec['mod_name']} </a>\n"; if (isset($arr[$rec['mid']])) showMenu($arr, $rec['mid'], $level+1); echo "</li>\n"; } echo "</ul>\n"; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 19.5 (Build 19523, 64bit)"> <meta name="author" content="Barand"> <meta name="creation-date" content="08/11/2021"> <title>Example</title> <style type='text/css'> li { padding: 8px; } .li0 { margin-left: 8px; } .li1 { margin-left: 28px; } .li2 { margin-left: 48px; } </style> </head> <body> <?= showMenu($mods, 0) ?> </body> </html>
  12. There's an example in this forum here
  13. According to my IP lookup table there are around 250,000 ranges of ip addresses for the UK so you could block if it is one of those. mysql> SELECT COUNT(*) FROM ip_lookup WHERE country = 'United Kingdom'; +----------+ | COUNT(*) | +----------+ | 257455 | +----------+ Alternatively you could check if the ip address is that of one of your 12 friend/family members and allow if it is.
  14. Read it again. It says it gives a warning if it isn't found (or isn't accessible). What is your error_reporting level?
  15. The manual explains it.
  16. Yes Unique customer id identifies the customer in the data Add new record to customer table Example +---------------+ | customer | +---------------+ | customer_id |-------+ +-----------------+ +----------------+ | customer_name | | | basket | | product | | email | | +-----------------+ +----------------+ | mobile | | | basket_id |-------+ +-----------------+ +-------| product_id | | etc | | | basket_date | | | basket_item | | | description | +---------------+ +------<| customer_id | | +-----------------+ | | price | +-----------------+ | | item_id | | +----------------+ +------<| basket_id | | | product_id |>-----+ | quantity | +-----------------+
  17. Good thinking, Batman! $vars = array_reverse(str_split(base_convert($input, 16, 2)));
  18. Ah yes. The "bury your head in the sand" method. If you can't see them, the errors don't exist.
  19. Well done. For the record... $input = 'B1'; // hex iput $decimal = base_convert($input, 16, 10); // convert to 177 for ($k=0; $k<8; $k++) { $vars[$k] = ($decimal & 2**$k) ? 1:0; }
  20. My mother taught me always to practise safe text and never accept links from strangers. Post the relevant code (using the <> button in the toolbar.) And tell us exactly what error message you are getting.
  21. These all have the same value +------------+------------+------------+ | Binary | Decimal | Hex | +------------+------------+------------+ | 10110001 | 177 | B1 | +------------+------------+------------+ In my code, setting $binary3 to any of these will give the same result $binary3 = 0b10110001; $binary3 = 177; $binary3 = 0xB1;
  22. You could treat that .env file as an ini file. For example... $envs = parse_ini_file('myproject.env'); echo $envs['API_KEY']; //-> secret key
  23. Still forgetting unpack(), for 8 bits to 8 vars $binary3 = 0b10110001; for ($k=0; $k<8; $k++) { $vars[$k] = ($binary3 & 2**$k) ? 1:0; } giving $vars = Array ( [0] => 1 [1] => 0 [2] => 0 [3] => 0 [4] => 1 [5] => 1 [6] => 0 [7] => 1 )
×
×
  • 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.