-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
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;
-
How to connect Oracle database in PHP from external network?
Barand replied to Abrar's topic in PHP Coding Help
Examples here -
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 | +-----+----------+--------------+-----------+
-
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>
-
There's an example in this forum here
-
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.
-
Read it again. It says it gives a warning if it isn't found (or isn't accessible). What is your error_reporting level?
-
The manual explains it.
-
One POS software for many customers, design database
Barand replied to nitiphone2021's topic in Application Design
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 | +-----------------+ -
Good thinking, Batman! $vars = array_reverse(str_split(base_convert($input, 16, 2)));
-
Ah yes. The "bury your head in the sand" method. If you can't see them, the errors don't exist.
-
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; }
-
Can anyone help me find the problem in my php code form?
Barand replied to rocknrolla's topic in PHP Coding Help
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. -
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;
-
You could treat that .env file as an ini file. For example... $envs = parse_ini_file('myproject.env'); echo $envs['API_KEY']; //-> secret key
-
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 )
-
Show multiple pages of PDFs in the same PDF file.
Barand replied to sashavalentina's topic in PHP Coding Help
Your program structure should look like this require 'tcpdf.php' database connection define class MYPDF handle POST request single query to get all required data initialize pdf doc foreach order_id add new page outout invoice for order_id end foreach output pdf doc -
... as this is an English-speaking site.
-
Try specifying the image path from your site's root, not the file system root. ie "/news/img/posts/"
-
Your first one is missing a } before the else. Syntax is if (condition) { do something } else { do something else } It looks like $em is not valid. Have you tried var_dump($em) to check what's in there? PS You could just... if ( ($em = filter_var($em, FILTER_VALIDATE_EMAIL)) === false ) { echo "Invalid format"; }
-
You have already posted this question. Closing.
-
This is the method I use, storing the data in an array indexed by parentId No need to store the "level". It works that out itself. Store the "left-margin" values for each level in the css.
-
Have you checked the value in $image_ext?
-
Make sure you have defined the function insert(). It's not a PHP function. (Or did you mean isset() ?)
-
If you are uploading a file you should be using the $_FILES array, not $_POST for the image.