Jump to content

thara

Members
  • Posts

    604
  • Joined

Everything posted by thara

  1. 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.
  2. 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.
  3. 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.
  4. Yes Sir I tried with array_chunk, but I couldn't get it to work as l expected.
  5. 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?
  6. Sir, I have checked that your above linked post, before asking this. But I couldn't figure it out.
  7. 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.
  8. Actually sir, category is not null, only brand would be NULL. then SKU should be : BI-IK0013
  9. 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.
  10. 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.
  11. Sir, lets assume, I will delete category 16 from the category table, according to my table it is a parent category. If there are two products belonging to that category in the product table, then what happens to the two category ids in that product, the category corresponding to that category id is not in the category table because it has already been deleted from the category table. Isn't that right?
  12. Yes sir its working... Thank you. One thing, I really want to see if the products related to this deleted category_id are in the product table and if so, set the category_id of those products to a general category. In this example, it is category number 1. Sir, Is there any possible way to modify this single query to reset the category_id in the product table also? Thanks again.
  13. Data from category table: +-------------+-----------+---------------------+-------------+ | category_id | parent_id | name | description | +-------------+-----------+---------------------+-------------+ | 1 | NULL | Products | NULL | | 2 | 1 | Computers | NULL | | 3 | 2 | Laptops | NULL | | 4 | 2 | Desktop Computers | NULL | | 5 | 2 | Tab PCs | NULL | | 6 | 2 | CRT Monitors | NULL | | 7 | 2 | LCD Monitors | NULL | | 8 | 2 | LED Monitors | NULL | | 9 | 1 | Mobile Phones | NULL | | 10 | 9 | LG Phone | NULL | | 11 | 9 | Anroid Phone | NULL | | 12 | 9 | Windows Mobile | NULL | | 13 | 9 | iPad | NULL | | 14 | 9 | Samsung Galaxy | NULL | | 15 | 1 | Digital Cameras | NULL | | 16 | 1 | Printers and Toners | NULL | | 17 | 14 | Galaxy S Series | NULL | | 18 | 14 | Galaxy Note Series | NULL | | 19 | 14 | Galaxy Z Fold2 5G | NULL | | 20 | 17 | Phone 1 | NULL | | 21 | 17 | Phone 2 | NULL | +-------------+-----------+---------------------+-------------+ Just think, I hava an array of category ids for delete like this: ids = [9,17,20]; Now I want to delete the category related to the above array and update the relevant child category. According to this example, the parent_id of the category_id 10,11,12,13,14 should be 1 The parent_id in category 21 should be updated to 14. In another case, suppose I delete category 9, 18 then all the relevant sub and sub sub categories should be updated as parant category. I hope somebody may help me out. Thank you
  14. I am trying to convert colors from Hex to HSL (Not HSL to Hex). I am using a PHP function for this purpose. But It's not working properly for some colors. For example for #e04c4c the HSL should be (0, 70%, 59%) which it isn't the case with the function. function hexToHsl($hex) { $red = hexdec(substr($hex, 0, 2)) / 255; $green = hexdec(substr($hex, 2, 2)) / 255; $blue = hexdec(substr($hex, 4, 2)) / 255; $cmin = min($red, $green, $blue); $cmax = max($red, $green, $blue); $delta = $cmax - $cmin; if ($delta === 0) { $hue = 0; } elseif ($cmax === $red) { $hue = (($green - $blue) / $delta) % 6; } elseif ($cmax === $green) { $hue = ($blue - $red) / $delta + 2; } else { $hue = ($red - $green) / $delta + 4; } $hue = round($hue * 60); if ($hue < 0) { $hue += 360; } $lightness = (($cmax + $cmin) / 2) * 100; $saturation = $delta === 0 ? 0 : ($delta / (1 - abs(2 * $lightness - 1))) * 100; if ($saturation < 0) { $saturation += 100; } $lightness = round($lightness); $saturation = round($saturation); //return "hsl(${hue}, ${saturation}%, ${lightness}%)"; return array($hue, $saturation, $lightness); } This is how I used it: $templatePrimaryColor = '#e04c4c'; $templatePrimaryColor = str_replace("#", "",$templatePrimaryColor); list($h,$s,$l) = hexToHsl($templatePrimaryColor); $primaryColor = "hsl(${h}, ${s}%, ${l}%)"; This is the output: echo '<pre>',print_r(hexToHsl($templatePrimaryColor)).'</pre>'; Array ( [0] => 0 [1] => 99 [2] => 59 ) 1 Does anyone know what is the problem there? Thank you.
  15. In my project I have a CSS custom variables like this: :root { --primary-color: #e04c4c; --secondary-color: #2c2c5e; --text-color: #d67900; } In my LESS files I have used LESS color functions to get more colors base on its primary and secondary. This is how its look like: .component1 { background: darken(--primary-color, 10%); } .component2 { background: lighten(--secondary-color, 5%); } But when I compile this, it gives an error like this? When googling I found a solution for SASS, but not for LESS. Can anybody tell me is there any possible workaround for this particular case? Thank you.
  16. Welcome to PHPFreaks!
  17. Welcome to PHPFreaks!
  18. I too love Barand, I know, my contributions is over 100 likes for him. Congratulations Sir!!! Anyway anybody have a looked at this profile?
  19. Basically I am having an array something like below, this array has number of categories and sub, sub sub categories. $categories = array( array('id' => 1, 'parent' => 0, 'name' => 'Category'), array('id' => 2, 'parent' => 1, 'name' => 'Category A'), array('id' => 3, 'parent' => 1, 'name' => 'Category B'), array('id' => 4, 'parent' => 1, 'name' => 'Category C'), array('id' => 5, 'parent' => 1, 'name' => 'Category D'), array('id' => 6, 'parent' => 1, 'name' => 'Category E'), array('id' => 7, 'parent' => 2, 'name' => 'Subcategory F'), array('id' => 8, 'parent' => 2, 'name' => 'Subcategory G'), array('id' => 9, 'parent' => 3, 'name' => 'Subcategory H'), array('id' => 10, 'parent' => 4, 'name' => 'Subcategory I'), array('id' => 11, 'parent' => 9, 'name' => 'Subcategory J'), ); Using this array I have created a nested <ul>. This is the recursive function I have used for : foreach ($categories as $category) { $id = $category['id']; $parent = $category['parent']; $name = $category['name']; //echo $name."<br>"; $cats[$parent][$id] = $name; } function displayList(&$cats, $parent, $current=0, $level=0) { switch ($level) { case 0: $class = "level_1 has_sub no_active"; $a_class = "c1"; break; case 1: $class = "level_2 has_sub no_active"; $a_class = "c2"; break; case 2: $class = "level_3 has_sub no_active"; $a_class = "c3"; break; } if ($parent==0) { foreach ($cats[$parent] as $id=>$nm) { if (isset($cats[$id])) { displayList($cats, $id, $current); } } } else { echo "<ul class='$class'>\n"; foreach ($cats[$parent] as $id=>$nm) { $clear = preg_replace('/[^a-zA-Z0-9\s]/', '', strip_tags(html_entity_decode($nm))); $pageName = strtolower(str_replace(' ', '-', $clear)); $link = $pageName.'.php'; echo "<li><a href='$link' class='$a_class $sel'><span>$nm</span></a>\n"; if (isset($cats[$id])) { displayList($cats, $id, $current, $level+1); } echo '</li>'; } echo "</ul>\n"; } } Look at that function, I have created a link for each category. Category name itself has used as page name. (Removing by special chars.) My question is, when this function executing I want to create folders for level one categories. Those category names should be used as folder names. Example from above array: category_a category_b category_c category_d category_e So, every sub category pages should be inside these parent category folders. Can I know is this possible in this function? Thank you.
  20. It doesn't matter. You can retrieve dates in whatever format you want Eg: SELECT DATE_FORMAT('2017-01-23', '%d/%m/%Y') But, you must however save all dates using the YYYY-MM-DD format as that is the only format that mysql date fields can accept (it is also the only format where you can sort into date order)..
  21. Since you are using bootstrap, You can easily create very smart and flexible dialog boxes with the Bootstrap modal plugin. Try this, if(isset($_SESSION['steamid'])){ echo '<button type="button" class="btn btn-lg btn-inverse btn-custom waves-effect waves-light" data-toggle="modal" data-target="#myModal"> Host a lobby </button>'; } Don't use <a> tag with button. Modal HTML: <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> ... modal contents here .... </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
  22. Here you need get_result() try it like this: if (!empty($date1_raw) && !empty($date2_raw)) { $sql = "SELECT * FROM costs WHERE costdate BETWEEN ? AND ? AND userid= ? ORDER BY costdate"; $stmt = $conn->prepare($sql); if ($stmt) { $stmt->bind_param("ssi", $date1_raw, $date2_raw, $session_id); $stmt->execute(); $result = $stmt->get_result(); printf("Number of rows: %d.\n", $stmt->num_rows); while($row = $result->fetch_assoc()) { echo $row['subcategory']; echo $row['costname']; // Added "€" sign infront of price !--> echo "€ " . $row['price']; echo $row['info']; // Added Date Function to convert format !--> echo date( "d/m/y",strtotime ($row['costdate'])); } } } NOTE: It is best practice to explicitly list every column you want returned instead of using select *, there are situations where you might want to save time and omit certain columns from the results.
  23. I am trying to remove folders and its files and sub folders using php. This is how I tried it. $dir = "../../images/$category_id/$delId"; $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); foreach($files as $file) { if ($file->isDir()){ rmdir($file->getRealPath()); } else { unlink($file->getRealPath()); } } rmdir($dir); This is working on php 5.5+, but is doesn't work in php 5.2.17. This is the error can I get when it running on php 5.2.17 Can anybody tell me how I get it to work on 5.2 also. Thank you.
  24. You have got an elegant solution for this from your other post. But, if you want to get hours and minutes into separate dropdown, we can do it something like this, <select name="hour"> <?php for ($i=0; $i<=23; $i++){ $i = sprintf('%02d', $i); echo "<option value='".$i."'>" . $i ."</option>\n"; } ?> </select> <select name="minutes"> <?php for ($i=0; $i<=59; $i++){ $i = sprintf('%02d', $i); echo "<option value='".$i."'>" . $i ."</option>\n"; } ?> </select>
×
×
  • 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.