Jump to content

thara

Members
  • Posts

    558
  • Joined

About thara

  • Birthday 02/05/1983

Profile Information

  • Gender
    Male
  • Location
    Panda

Contact Methods

  • Skype
    tharangagamage

Recent Profile Visitors

11,037 profile views

thara's Achievements

Advanced Member

Advanced Member (4/5)

5

Reputation

  1. Sir, I do not see any error in the query pointed out by you. Sir, Is it possible to change that single query by setting the permissions to 1 only for the parent and child modules selected by the user?
  2. Sir, I am having a problem with your above single query solution. As you have mentioned, it become permission column to 1, for selected parents and its all child modules. Look at this Example: Query Result: SELECT m.module_id , name , IFNULL(parent, 0) , CASE WHEN p2.module_id IS NULL THEN CASE WHEN p.module_id IS NULL THEN 0 ELSE 1 END ELSE 1 END as permission FROM module m LEFT JOIN user_permission p ON m.module_id = p.module_id AND p.user_id = 38 LEFT JOIN user_permission p2 ON m.parent = p2.module_id AND p2.user_id = 38 ORDER BY m.module_id ; +-----------+------------------+-------------------+------------+ | module_id | name | IFNULL(parent, 0) | permission | +-----------+------------------+-------------------+------------+ | 1 | User Modules | 0 | 0 | | 2 | Items | 1 | 0 | | 3 | Add New Item | 2 | 0 | | 4 | View Item | 2 | 0 | | 5 | Category | 2 | 0 | | 6 | Brand | 2 | 0 | | 7 | Unit | 2 | 0 | | 8 | Purchase | 1 | 1 | | 9 | Add New Purchase | 8 | 1 | | 10 | view Purchase | 8 | 1 | | 11 | Due Invoice | 8 | 1 | | 12 | Return | 8 | 1 | | 13 | Purchase Log | 8 | 1 | | 14 | Inventory | 1 | 0 | | 15 | Stock Transfer | 14 | 0 | | 16 | Stock Adjustment | 14 | 0 | | 17 | Batch Control | 14 | 0 | | 18 | Stock Take | 14 | 0 | +-----------+------------------+-------------------+------------+ Sir, How can we make permision column to 1 only for selected modules?
  3. Sir, I tried it something like this: My parent and child module arrays changed as below: [pmod] => Array ( [2] => 1 [8] => 1 [14] => 1 ) [cmod] => Array ( [8] => Array ( [9] => 1 [10] => 1 [11] => 1 ) [14] => Array ( [15] => 1 [16] => 1 ) ) This is my PHP: // Insert into "user_permission" table: if(!empty($_POST['pmod']) && !empty($_POST['cmod'])) { $modCheked=[]; foreach ($_POST['cmod'] as $pid => $child) { foreach ($child as $cid => $value) { array_push($modCheked, $pid, $cid); $modules = array_unique($modCheked); } } $sql = "INSERT INTO user_permission (module_id,user_id) VALUES (?,?)"; $stmt = $pdo->prepare($sql); foreach ($modules as $k => $mid) { $module_id = intval($mid); $stmt->execute([$module_id, $lastInsertID]); } } From this code, it is inserted all IDs from `cmod` array into DB.
  4. Sir, I have showing a message to user that saying don't select only parent in my front end. But if they select only parent deliberately or by mistake, I need to ignore it from backend. Thats why I am looking for such a solution.
  5. Thank you sir, One thing, Can we set all permission to 0 including parent, if a user select only parent module. In this case it is not needed parent permission, if user select only parent.
  6. Thank you Sir, I have tried, but my array_chunk was in wrong loop. (I have tried it inside second foreach) I have another question to clarify with you. When I trying to edit user selected checkboxes, I am currently using 2 queries like this: // Get All Modules: $sql ="SELECT module_id, name, IFNULL(parent, 0) FROM module ORDER BY module_id"; $res = $pdo->query($sql); while (list($id, $name, $parent) = $res->fetch(PDO::FETCH_NUM)) { $data[$parent][] = array('id'=>$id, 'name'=>$name); } // Gell User Selected Modules: $sql ="SELECT module_id FROM user_permission WHERE user_id = ? ORDER BY module_id"; $stmt = $pdo->prepare($sql); $stmt->execute([$pageID]); while (list($module_id) = $stmt->fetch(PDO::FETCH_NUM)) { $mid[] = $module_id; } To display selected checkbox in edit form, I am doing it like this inside 1st and 3rd foreach. $checked = (in_array($main['id'], $mid)) ? " checked='checked'" : ''; $checked = (in_array($m['id'], $mid)) ? " checked='checked'" : ''; Sir, may I know, is there a way to do this with single query? Left Join didn't work for me.
  7. Sir, I need single <tr> with 4 <td> for one module. (for parent and child). Chuck of 3 childs need to be get into one td. That is the issue I have.
  8. Yes Sir I tried with array_chunk, but I couldn't get it to work as l expected.
  9. Thank you Sir. Your demostration was really helped me to get it started. This is how I tried it so far: $sql ="SELECT module_id , name , IFNULL(parent, 0) FROM module ORDER BY module_id"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->execute(); $stmt->store_result(); $numrows = $stmt->num_rows; if ($numrows >= 1) { $stmt->bind_result($modId,$name,$parent); while ($stmt->fetch()) { $modList[$parent][] =['id' => $modId, 'name' => $name]; } $stmt->close(); unset($stmt); } } $tbl = '<table class="table table-bordered">'; foreach ($catList[1] as $main) { $tbl .= "<tr><td>{$main['name']}</td><td>"; //echo $main['name'] . '<br>'; foreach ($catList[$main['id']] as $mod) { //$modItem = array_chunk($mod, 3); $tbl .= "{$mod['name']}"; //echo "- {$mod['name']}<br>"; } $tbl .= "</td></tr>"; } $tbl .= "</table>"; echo $tbl; This is ok, But there is a problem. Sir may I know how I get 3 sub modules per each <td> in the table?
  10. Sir, I have checked that your above linked post, before asking this. But I couldn't figure it out.
  11. I do have a sql table named "module" and a parent module may have a sub module. Each parent module can have a maximum of 9 sub modules of three per <td>. This is how this "module" table looks like: +-----------+------------------+----------+------+--------+---------------------+ | module_id | name | page_url | icon | parent | created_date | +-----------+------------------+----------+------+--------+---------------------+ | 1 | User Modules | | NULL | NULL | 2021-07-21 11:46:16 | | 2 | Items | | NULL | 1 | 2021-07-21 11:46:16 | | 3 | Add New Item | | NULL | 2 | 2021-07-21 11:46:16 | | 4 | View Item | | NULL | 2 | 2021-07-21 11:46:16 | | 5 | Category | | NULL | 2 | 2021-07-21 11:46:16 | | 6 | Brand | | NULL | 2 | 2021-07-21 11:46:16 | | 7 | Unit | | NULL | 2 | 2021-07-21 11:46:16 | | 8 | Purchase | | NULL | 1 | 2021-07-21 11:46:16 | | 9 | Add New Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 10 | view Purchase | | NULL | 8 | 2021-07-21 11:46:16 | | 11 | Due Invoice | | NULL | 8 | 2021-07-21 11:46:16 | | 12 | Return | | NULL | 8 | 2021-07-21 11:46:16 | | 13 | Purchase Log | | NULL | 8 | 2021-07-21 11:46:16 | | 14 | Inventory | | NULL | 1 | 2021-07-21 11:46:16 | | 15 | Stock Transfer | | NULL | 14 | 2021-07-21 11:46:16 | | 16 | Stock Adjustment | | NULL | 14 | 2021-07-21 11:46:16 | | 17 | Batch Control | | NULL | 14 | 2021-07-21 11:46:16 | | 18 | Stock Take | | NULL | 14 | 2021-07-21 11:46:16 | +-----------+------------------+----------+------+--------+---------------------+ My desired HTML table layout looks somthing similar to this attach image. I would like to know how we can do it in php, if is possible. Thank you.
  12. Actually sir, category is not null, only brand would be NULL. then SKU should be : BI-IK0013
  13. I need to create the unique SKU (Stock Keeping Unit) name for each products mixed with product.id,product.name,product.category and product.brand. There is no problem to do it, i.e.: SKU for a product with id=13, name=Bio Clean green and category=INSECTS KILLERS brand=HARPIC becomes : BI-IKHA0013 This is how I tried: $inm = "Bio Clean green500ml"; $cnm = "INSECTS KILLERS"; $bnm = "HARPIC "; echo SKU_gen($inm, $cnm,$bnm,20).'<br>'; function SKU_gen($pname, $cat=null, $brand=null, $id = null, $l = 2){ $results = ''; // empty string $str1 = array_shift(explode(' ',$pname)); $str1 = strtoupper(substr($str1, 0, $l)); $str2 = array_shift(explode(' ',$cat)); $str2 = strtoupper(substr($str2, 0, $l)); $str3 = array_shift(explode(' ',$brand)); $str3 = strtoupper(substr($str3, 0, $l)); $id = str_pad($id , 4, 0, STR_PAD_LEFT); $results .= "{$str1}-{$str2}{$str3}{$id}"; return $results; } But this function is not working as expected when category of brand values become NULL.
  14. Sir, Thanks for response I was thinking about your first option and setting procut category to a new common one. Sir is there a way to do this by modifing above query ? Thank you.
×
×
  • 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.