Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/12/2021 in all areas

  1. Yes, it is possible to make that query happen with the query builder. Have you looked around to see what kinds of options you have available to use?
    1 point
  2. So you want a query like UPDATE posts SET count = count + 1 WHERE id = $id
    1 point
  3. You can't both change and not-change the value. Explain what you're trying to do in more detail.
    1 point
  4. This "rows": {...} and this "rows": [{...}] are two distinctly different things. To figure out what you have to use to access something, work from the outside in. 1 { 2 "column-names": [ 3 "address1", 4 "address2", 5 "address3", 6 "postcode", 7 ... 8 ], 9 "rows": [ 10 { 11 "address": "123, Imaginary Road", 12 "someotherdata": dataset, 13 ..., 14 "postcode": "H3L L00" 15 } 16 ] 17 } If you want the "address" on line 11 then you have to go through: 1. The outermost thing is an object (line 1) 2. The "rows" member is an array (line 9) 3. The first item in that array is an object (line 10) 4. The "address" member Since you told json_decode() that you want objects to be converted into arrays, then that means you: 1. Start with the thing returned to you by json_decode(), which will be an array 2. Get the "rows" member 3. Get the first member, which would be the 0th 4. Get the "address" member In the real world, if you have something called "rows" that is a JSON [ ] array then you probably shouldn't be using direct offsets on it (eg, 0) but rather a loop to get all the things inside it.
    1 point
  5. This is one reason some prefer to use absolute paths when including files, another is that it will be more adaptable than relying on include paths. The idea is that you store the "base path" of your active project/script, which you can then use to work out the paths for the rest of your files — either as a global constant or a variable you pass around as needed. From PHP 5.5 and onwards, the following should work: define('BASE_PATH', rtrim(preg_replace('#[/\\\\]{1,}#', '/', __DIR__), '/') . '/');
    1 point
  6. 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 | +-----+----------+--------------+-----------+
    1 point
  7. 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>
    1 point
  8. While possible to do in object form like that, it would be easier to have json_decode give you an array instead. $json_string = '{"name":"Jeff","age":20,"active":true,"column-names":["title1","title2"]}'; $array = json_decode($json_string, true); printf('All done! Welcome to Homepage %s', $array["column-names"][1]);
    1 point
  9. Have you done a search of your script for another call to unlink?
    1 point
  10. Read it again. It says it gives a warning if it isn't found (or isn't accessible). What is your error_reporting level?
    1 point
  11. It doesn't. If you don't provide a path when including a file, php will search for the file in the locations defined in the include_path. I'd guess that your public_html directory is part of this. var_dump(get_include_path());
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • 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.