-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
Here's an example script using this test data +------+---------+-------+ | id | product | price | +------+---------+-------+ | A001 | Widget | 10.99 | | B002 | Gizmo | 3.49 | | C003 | Thingy | 56.25 | | D444 | Wotsit | 2.25 | +------+---------+-------+ Code <?php require 'db_inc.php'; if ($_SERVER['REQUEST_METHOD']=='POST') { echo "Submitted form data:<br>"; echo '<pre>' . print_r($_POST, 1) . '</pre>'; // process the data here } $res = $db->query("SELECT product_id as id , product_name as product , price FROM product "); $tdata = ''; foreach ($res as $row) { $tdata .= <<<TDATA <tr> <td>{$row['product']}</td> <td class='price ra' data-id='{$row['id']}' data-val='{$row['price']}'>{$row['price']} €</td> <td class='ra'> <input type='number' class='qty' data-id='{$row['id']}' name='qty[{$row['id']}]' value='0'></td> <td class='total ra' data-id='{$row['id']}' >0 €</td> </tr> TDATA; } ?> <html> <head> <title>Sample</title> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> $().ready( function() { $(".qty").change( function() { var qty = $(this).val() var id = $(this).data("id") var price = $(".price[data-id="+id+"]").data("val") var tot = (qty * price).toFixed(2) $(".total[data-id="+id+"]").html(tot+" €") }) }) </script> <style type='text/css'> table { width: 600px; } tr { height: 55px; vertical-align: middle; } th, td { padding: 0 16px; } .qty { width: 50px; } .ra { text-align: right; } </style> </head> <body> <form method='post'> <table> <tr><th>Produkt</th> <th>Einzelpreis</th> <th>Menge</th> <th>Gesamtpreis</th> </tr> <?=$tdata?> </table> <input type='submit' value='Submit'> </form> </body> </html> Sample output
-
Of course you can <style type='text/css'> .w3-vomit { background-color: #f8b9ce; color: #c4ff4d; } </style> <h1 class="w3-vomit w3-padding">Example heading</h1>
-
insert data in form element does not insert into my tables?
Barand replied to sashavalentina's topic in PHP Coding Help
These fields shouldn't even be in the cart table, they should be retrieved from the product table when required. All you need are the ids and quantity (you certainly don't need the product title 3 times!). Instead of a query to see if there is already a record for the user/product you should define that combination of columns as UNIQUE. Having done that you use a single query for the inserts and updates INSERT INTO cart (user_id, product_id, seller_id, quantity) VALUES (? , ? , ? , ?) ON DUPLICATE KEY UPDATE quantity = VAUES(quantity); -
onclick of an html <a> tag change what $table will be used
Barand replied to Elara's topic in PHP Coding Help
Your links would be in the form <a href='djams_rmc.php?branch=X'> where X is the id of the branch. Then, in your appintments page (djams_rmc.php), you get the required branch with $id = $_GET['branch']; $query = $db->prepare("SELECT whatever FROM appointment WHERE branch_id = ?"); $query->execute([ $id ]); -
onclick of an html <a> tag change what $table will be used
Barand replied to Elara's topic in PHP Coding Help
Have one appointment table for all branches. Add an extra column (indexed) for "branch_id" so you know which branch each row belongs to. Then all your query needs is "WHERE branch_id = ?" and no need to switch tables. +-----------------+ | branch | +-----------------+ +------| branch_id | | | branch_name | +------------------+ | +-----------------+ | appointment | | +------------------+ | | app_id | | | branch_id |>---------+ | app_date_time | | description | | etc | +------------------+ -
onclick of an html <a> tag change what $table will be used
Barand replied to Elara's topic in PHP Coding Help
Why is the data for the different branches in different tables? Is the structure of the data different for each branch? -
Put values to text fields after submit
Barand replied to Temporary_Failure's topic in PHP Coding Help
In two words - variable scope. Variables created inside a function are not available outside of it. Have your function return an array return ["hinta" => $hinta, "stock" => $stock ]; Call $data = func(); then put those array values in your fields. [edit] PS Just return $haku. -
You have shown us your html for the login and php code which processes the login. Your code references three php file login.php home.php index.php What we don't know is where the code you have shown us is placed. Nor do we know what exactly which you are running when you see the error. We do not know the flow that is taking place from one to the next, and given your problem, I'm not sure you do either. Typical flow is like this, but it looks like you are starting at "X"
-
Getting all data in a particular timeframe for the respective agent_id
Barand replied to JJM50's topic in MySQL Help
Data +----+---------+----------+-----------+---------------------+ | id | refno | agent_id | status_to | logtime | +----+---------+----------+-----------+---------------------+ | 1 | LP01552 | 57 | Draft | 2021-10-05 10:33:12 | | 2 | LP02552 | 57 | Unpublish | 2021-10-04 10:33:12 | | 3 | LP03552 | 57 | Draft | 2021-10-05 10:33:12 | | 4 | LP04552 | 57 | Publish | 2021-10-09 10:33:12 | | 5 | LP05552 | 57 | Draft | 2021-10-10 10:33:12 | | 6 | LP06552 | 57 | Publish | 2021-10-11 10:33:12 | | 7 | LP07552 | 57 | Action | 2021-10-06 10:33:12 | | 8 | LP08552 | 58 | Draft | 2021-10-02 10:33:12 | | 9 | LP09552 | 58 | Unpublish | 2021-10-11 10:33:12 | | 10 | LP09652 | 58 | Publish | 2021-10-08 10:33:12 | | 11 | LP08542 | 59 | Draft | 2021-10-06 10:33:12 | | 12 | LP09542 | 59 | Unpublish | 2021-10-06 10:33:12 | | 13 | LP09642 | 59 | Draft | 2021-10-07 10:33:12 | +----+---------+----------+-----------+---------------------+ Code <?php $res = $db->prepare("SELECT agent_id as Agent , SUM(status_to = 'Draft') as Draft , SUM(status_to = 'Unpublish') as Unpublish , SUM(status_to = 'Publish') as Publish , SUM(status_to = 'Action') as Action FROM crm_log WHERE logtime BETWEEN ? AND ? GROUP BY agent_id "); $res->execute( [ '2021-10-01', '2021-10-31' ] ); $data = ''; $row = $res->fetch(); $heads = "<tr><th>" . join('</th><th>', array_keys($row)) . "</th></tr>\n"; do { $data .= "<tr><td>" . join('</td><td>', $row) . "</td></tr>\n"; } while ($row = $res->fetch()); ?> <table border='1' style='border-collapse: collapse; width: 500px'> <?=$heads?> <?=$data?> </table> Output- 1 reply
-
- 1
-
-
- codeigniter
- mysql
-
(and 1 more)
Tagged with:
-
https://fontawesome.com/v4.7/icon/angle-left
-
Your biggest problem is the lack of closing curlies } after each style spec. As for the quotes, do them the way that works.
-
FYI If you have a div inside the 8-col td, then it works with display:block <tr > <td colspan='8'> <div class='more' id='details{$cnt}' >lorem fucking ipsum wahoo baby - {$cnt}</div> </td> </tr>
-
Instead of changing the display to "block" when you click the button, set it to "display: table-cell;" <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> function showDetails(cnt) { $(".more").css("display", "none"); // hide all var details = "details"+cnt; var x = document.getElementById(details); if (x.style.display === "none") { x.style.display = "table-cell"; // display requested one } else { x.style.display = "none"; } } </script>
-
If I put the style='display: none' back, I get Apart from that one inline style I am using no css, so something in yours could be screwing up.
-
How do you know with the display: none ? If I supply some dummy values, remove the display:none and add borders to the table so I can see what's happening... $rank = $image = $name = $final_worth = $country = $source = $cnt = $class = $last_change = 'X'; $html = " <tr class='mt-2'> <td>{$rank}.</td> <td><img src='{$image}' height='75' width='75'></td> <td>{$name}</td> <td class='bold'>\${$final_worth}B</td> <td class='{$class}'>\${$last_change}</td> <td>{$country}</td> <td>{$source}</td> <td><button class='bg-color-primary text-color-third px-2' id='more_btn' onclick='showDetails({$cnt})'>More</button></td> </tr> <tr > <td colspan='8' id='details{$cnt}' >lorem fucking ipsum wahoo baby - {$cnt}</td> </tr> "; I see
-
try changing that to <tr > <td colspan='8' id='details'>lorem fucking ipsum wahoo baby</td> </tr> If it ain't in a cell, it's rejected from the table, which is why it appears above.
-
That line in your onchange function concerns me. If it was generated when PHP was executing. how does it relate to the id of the product the user is clicking in the browser?
-
Because there is a mix of old (edited) records and new ones, the simplest way to update the DB is with INSERT INTO tablename (id, list_order, food, price) VALUES ( ?, ?, ?, ?) ON DUPLICATE KEY UPDATE list_order = VALUES(list_order), food = VALUES(food), price = VALUES(price); I too normally like the food[x][field] naming method, but this insert/update method would require that all the new ones all had zero id. As array keys can't be duplicated then using the id in the field naming becomes a problem. I would also use a hidden id field but go with List order <input type="text" name="list_order[]" value="<?= $result['list_order']?>"><br> Food item <input type="text" name="food[]" value="<?= $result['food']?>"><br> Price (each) <input type="text" name="price[]" value="<?= $result['price']?>"> <input type="hidden" name="id[]" value="<?= $result['id']?>"> using 0 instead of $result['id'] for the id values in the new ones
-
But have you tried the method I flowcharted for you?
-
seperate grouped radio button for each photo - keep/delete options
Barand replied to jasonc's topic in PHP Coding Help
Think of radio buttons as menu options. They need the same name (so the browser knows they are part of the same menu) but different values that the user selects. Use the id (image id I presume) as part of the name to group them <input type="radio" name="action[<?=$result['id']?>]" value="A"> Approve <input type="radio" name="action[<?=$result['id']?>]" value="D"> Delete Then to process the form data foreach ($_POST['action'] as $id => $action) { if ($action == 'D') { // delete image whose ID is $id } elseif ($action == 'A') { // approve image whose ID is $id } } -
Inserting a substring value into an already existing entry
Barand replied to JJM50's topic in MySQL Help
Firstly, I doubt anyone is clicking a link from a first-time poster. Second, what you are doing, updating with parts of a column, is indicative of problems in the database design. What is the structure of those two tables and what does the data look like in the relevant columns?- 1 reply
-
- 1
-
-
<?php header("Location: Startseite.php"); ?>
-
OK. Back to your original file format. I showed you the logic to use in your code. Have you even attempted that method yet? (it's only about six or seven lines of code) If you at least try, you get more help. Or are you just upset because no one wrote the actual code for you
-
When I last worked with LDAP, I just used to interrogate the network LDAP servers to see who was logged in and what groups/depts etc they were in. ($_SERVER['login_user'])
-
That line is setting the session value to an array. did you mean = $_POST['username'] ?