-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
If user selects only parent module and you set parent permission to 0 (ie remove permission record) how do you then know user has set parent permission?
-
Yes - just like those sample links in my first reply
-
Simple example products.php - list products with links containing the product's' id $res = $db->query("SELECT prod_id , description FROM featuredlist; "); $output = ''; foreach ($res as $row) { $output .= <<<HTML <div class='product'> <a href="detail.php?id={$row['prod_id']}"> {$row['description']} </a> </div>\n HTML; } detail.php $prod_id = $_GET['id'] ?? 0; // get product id from the query string if ($prod_id != 0) { $stmt = $db->prepare("SELECT description FROM featuredlist WHERE prod_id = ? "); $stmt->execute([$prod_id]); $row = $stmt->fetch(); // output product details here }
-
You appear to use $_SESSION['prod_id'] every time. When does that get changed? You should be using the id from the product's link each time. PS USe code tags (<> button in toolbar)
-
Suppose your product page has several images +------------------+ +------------------+ | | | | | Product A | | Product B | | | | | | | | | | | | | | href = | | href = | | detail.php?id=1 | | detail.php?id=2 | | | | | +------------------+ +------------------+ +------------------+ +------------------+ | | | | | Product C | | Product D | | | | | | | | | | | | | | href = | | href = | | detail.php?id=3 | | detail.php?id=4 | | | | | +------------------+ +------------------+ Apply a link from each image to the detail.php page passing the id of the product. In detail.php, get the id passed in the link query your database tables for the product info using that id display the product details
-
Here's the single query. If the user has permission to use a module, the permission column = 1 otherwise 0. If the user has permission to use a module's parent module then the user can use all the children of the parent. 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 = 2 LEFT JOIN user_permission p2 ON m.parent = p2.module_id AND p2.user_id = 2 ORDER BY m.module_id ;
-
I am not a great fan of ENUM, preferring to have choices like your "media type" in a table with an id, and store the id in the data table as a foreign key. Having such values in a table makes it easy to form a list of choices for the user, a task which is a PITA if the values are stored as enum.
-
I need help in generating school terminal results using pin
Barand replied to Sunyside's topic in PHP Coding Help
I see you are using someone else's posted output image - do you have anything of your own so far for this project, such as code ? What bit are you having a problem with (apart from getting someone to give you free code)? -
I'd go for an array instead of separate variables created using $$. $fields = array( 'address' , 'email' , 'phone' , 'city' ); foreach ($fields as $name) { $data[$name] = "whatever"; } then you can subsequently $stmt = $pdo->prepare("INSERT INTO user (address, city, email, phone) VALUES (:address, :city, :email, :phone) "); $stmt->execute($data);
-
Is there a better way to do php ajax live search from the database?
Barand replied to imgrooot's topic in PHP Coding Help
Adding to dropdown... <script type='text/javascript'> $().ready(function() { $("#term").keyup(function() { var term = $(this).val() $.get( "", {"term":term}, function(resp) { $("#city").html("") $.each(resp, function(k,v) { var city = $("<option>", {"value":v.cityid, "text": v.cityname + ', ' + v.provincename + ', ' + v.countryname}) $("#city").append(city) }) }, "JSON" ) }) }) </script> </head> <body> <form> Search<br> <input type='text' name='term' id='term' style='width: 400px;'> <br> <select name='city' id='city' size='10' style='width: 400px;'></select> </form> </body> </html> -
Is there a better way to do php ajax live search from the database?
Barand replied to imgrooot's topic in PHP Coding Help
BTW, over half your php code was creating unnecessary variables and transferring data from one array to another just to rename the keys. All you needed was $get_city_select = $db->prepare("SELECT c.city_id as cityid , c.city_name as cityname , p.province_name as provincename , co.country_name as countryname FROM city c LEFT JOIN province p ON c.province_id = p.province_id LEFT JOIN country co ON p.country_id = co.country_id WHERE city_name LIKE :param"); $get_city_select->bindParam(':param', $param_term); $get_city_select->execute(); $result_city_select = $get_city_select->fetchAll(PDO::FETCH_ASSOC); exit(json_encode($result_city_select)); -
-
Having chunked your array of children, loop through the chunks putting the submodules from each chunk into a <td>..</td>. (You might want to pad the child array to 9 first to ensure you always get 3 columns of 3. Tables like their rows to have the same number of cells)
-
For the benefit of those of us who can't read your mind, what were you expecting? In what way did it not work?
-
I'd use array_chunk, as you were planning to do.
-
Your file name is index.html and not index.php. You need a php file for php code to be executed.
-
Your array will look like this Each id in the array items points to the index of that items child array [edit]... To get you started foreach ($data[1] as $main) { echo $main['name'] . '<br>'; foreach ($data[$main['id']] as $mod) { echo "- {$mod['name']}<br>"; } }
-
Looking closer at your data, the function would not need to be recursive. A simple nested loop would do once you have the array as you don't have an indeterminate number of levels (just 2)
-
-
BULLSH*T. If you actually read @kicken's reply you will see he is using two different tables in his example.
-
Show categories with subcategories (parent, child)?
Barand replied to Guldstrand's topic in MySQL Help
Example here -
Just think how much quicker we coud have got you there if you'd said what you were really trying to! The answer to that question should have been "No, I want all those with a time after 6pm today"
-
GROUP BY not working properly when used with multiple joined tables
Barand replied to imgrooot's topic in PHP Coding Help
Answer: The bits you got wrong are... The SELECT clause The WHERE clause Probably the JOIN clauses too (but without knowing what you expect as output if a user has no city or category data, it's impossible to be sure) -
Can you attach a dump of your data?