Jump to content

Adamhumbug

Members
  • Content Count

    74
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Adamhumbug

  • Rank
    Regular Member
  1. I do have one further question - i did stray a little from exactly what you did and i think you may have addressed what i am about to ask in your middle block of code but i didnt quite get it. when posting, i am getting undefined variable. while ($row = mysqli_fetch_array($result)){ $moneyid = $row['money_id']; echo "<tr>"; echo "<td style='width:70%;'>".$row['money_item']; echo "<input type='hidden' class='moneyValue' value=".$row['money_value']." data-id='".$moneyid."' name='moneyId[]'></td>"; echo "<td class='text-center'><input class='Qty up text-center' value='".$row['money_qty']."' name='moneyQty".$moneyid."' type='text' data-id='".$moneyid."'></td>"; echo "<td><span class='moneyTotal' data-id='".$moneyid."'></span></td>"; echo "</tr>"; } echo "<tr><td colspan='2'>Total</td><td id='grandTotal'>Grand Total</td></tr>"; if ($_SERVER['REQUEST_METHOD']=='POST') { $jobId = $_SESSION['current_job_id']; if(isset($_POST['moneyQty'])){$qty = $_POST['moneyQty'];} // prepare insert query $stmt = $conn->prepare("INSERT INTO ssm_money_order (money_qty, job_id, money_id) VALUES (?,?,?) ON DUPLICATE KEY UPDATE money_qty = VALUES(money_qty)" ); foreach ($_POST['moneyId'] as $k => $mid) { if ($qty[$k] > 0) { $stmt->bind_param("iii", $qty[$k], $jobId, $mid); $stmt->execute(); } } } The above is the php on the show page and the sql on the update request. I am getting undefined variable on: if(isset($_POST['moneyQty'])){$qty = $_POST['moneyQty'];} Which i understand as i have changed the name of the input from name='moneyQty[]' to name='moneyQty".$moneyid."' but i am not sure if i just change the foreach that i have to what you said or if there is more changes to be made. To be honest i dont 100% understand that for each loop
  2. This is perfect, thank you so much - the explanations were great as well so thanks again!!
  3. I have made some changes. while ($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td style='width:70%;'>".$row['money_item']."</td>"; echo "<input id='moneyId".$i."' type='hidden' name='moneyId[]' data-amount='".$row['money_value']."' value='".$row['money_id']."'>"; echo "<td class='text-center'><input id='moneyquantity".$i."' class='Qty up text-center' value='".$row['money_qty']."' name='moneyQty[]' type='text'></td>"; echo "<td><span id='moneyTotal".$i."'></span></td>"; echo "</tr>"; $i++; } <input data-amount="90.00" id="moneyId1" name="moneyId[]" type="hidden" value="1"><input data-amount="0.00" id="moneyId2" name="moneyId[]" type="hidden" value="5"><input data-amount="0.00" id="moneyId3" name="moneyId[]" type="hidden" value="6"><input data-amount="1000.00" id="moneyId4" name="moneyId[]" type="hidden" value="4"><input data-amount="150.00" id="moneyId5" name="moneyId[]" type="hidden" value="2"><input data-amount="300.00" id="moneyId6" name="moneyId[]" type="hidden" value="3"> <table> <tr class="text-center"> <th>Item</th> <th>Quantity</th> <th>Line Value</th> </tr> <tr> <td style="width:70%;">£90 Float Bag</td> <td class="text-center"><input class="Qty up text-center" id="moneyquantity1" name="moneyQty[]" type="text" value="3"></td> <td><span id="moneyTotal1">£270</span></td> </tr> <tr> <td style="width:70%;">First Aid Kit</td> <td class="text-center"><input class="Qty up text-center" id="moneyquantity2" name="moneyQty[]" type="text" value=""></td> <td><span id="moneyTotal2"></span></td> </tr> <tr> <td style="width:70%;">Waiter Pad</td> <td class="text-center"><input class="Qty up text-center" id="moneyquantity3" name="moneyQty[]" type="text" value=""></td> <td><span id="moneyTotal3"></span></td> </tr> <tr> <td style="width:70%;">£1000 Change Bag</td> <td class="text-center"><input class="Qty up text-center" id="moneyquantity4" name="moneyQty[]" type="text" value=""></td> <td><span id="moneyTotal4"></span></td> </tr> <tr> <td style="width:70%;">£150 Float Bag</td> <td class="text-center"><input class="Qty up text-center" id="moneyquantity5" name="moneyQty[]" type="text" value=""></td> <td><span id="moneyTotal5"></span></td> </tr> <tr> <td style="width:70%;">£300 Change Bag</td> <td class="text-center"><input class="Qty up text-center" id="moneyquantity6" name="moneyQty[]" type="text" value=""></td> <td><span id="moneyTotal6"></span></td> </tr> </table> var qty = document.getElementById("moneyquantity1").value; var amount = document.getElementById("moneyId1").getAttribute("data-amount"); var total ='£'+ qty * amount; $("#moneyTotal1").append(total); i have not added the handler yet to make it update live but it does what i want for one line.
  4. Sorry, i repeated myself there. I wanted to multiply the amount by the qty and show this value on the screen. This will have no impact on the values that are stored in the database but will just be used on screen to show the user the total amount.
  5. Thanks both. I added the following to my database connection and that has done the trick. mysqli_set_charset( $conn, 'utf8'); Thanks again, Kind Regards Adam
  6. I am having an issue with £ that i have in my database showing on my webpage as a triangle ?. I have my database encoded as utf8_general_ci and i declare <meta charset="UTF-8"> in my head. Is there something that i am missing here? Help is appreciated. Kind Regards Adam
  7. HI All, I am wanting to do some maths with JS on my website that is built dynamically from information held in my database. It is going to be a very simple multiplication but i am struggling to know how to write the JS to know which line to run on. The code that builds it is the following: while ($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td style='width:70%;'>".$row['money_item']."</td>"; echo "<input type='hidden' name='moneyId[]' amount='".$row['money_value']."' value='".$row['money_id']."'>"; echo "<td class='text-center'><input class='Qty up text-center' value='".$row['money_qty']."' name='moneyQty[]' type='text'></td>"; echo "<td><span id='moneyTotal'>This</span></td>"; echo "</tr>"; } and it looks like this when built: <tbody> <tr class="text-center"> <th>Item</th> <th value="0">Quantity</th> <th>Line Value</th> </tr> <tr> <td style="width:70%;">90.00 Float Bag</td> <input type="hidden" name="moneyId[]" amount="90.00" value="1"> <td class="text-center"><input class="Qty up text-center" value="100" name="moneyQty[]" type="text"></td> <td><span id="moneyTotal">This</span></td> </tr> <tr> <td style="width:70%;">1000.00 Change Bag</td> <input type="hidden" name="moneyId[]" amount="1000.00" value="4"> <td class="text-center"><input class="Qty up text-center" value="" name="moneyQty[]" type="text"></td> <td><span id="moneyTotal">This</span></td> </tr> <tr> <td style="width:70%;">150.00 Float Bag</td> <input type="hidden" name="moneyId[]" amount="150.00" value="2"> <td class="text-center"><input class="Qty up text-center" value="" name="moneyQty[]" type="text"></td> <td><span id="moneyTotal">This</span></td> </tr> <tr> <td style="width:70%;">300.00 Change Bag</td> <input type="hidden" name="moneyId[]" amount="300.00" value="3"> <td class="text-center"><input class="Qty up text-center" value="" name="moneyQty[]" type="text"></td> <td><span id="moneyTotal">This</span></td> </tr> <tr> <td style="width:70%;">First Aid Kit</td> <input type="hidden" name="moneyId[]" amount="0.00" value="5"> <td class="text-center"><input class="Qty up text-center" value="" name="moneyQty[]" type="text"></td> <td><span id="moneyTotal">This</span></td> </tr> <tr> <td style="width:70%;">Waiter Pad</td> <input type="hidden" name="moneyId[]" amount="0.00" value="6"> <td class="text-center"><input class="Qty up text-center" value="" name="moneyQty[]" type="text"></td> <td><span id="moneyTotal">This</span></td> </tr> </tbody> I am wanting to multiply the amount by the amount (which in the first row is 90.00) by the qty which is an input box. I can work out how to do the standard maths if there was only one row but i dont know how to get this to run on each line and update the money total. Help as always is appreciated. Kind Regards Adam
  8. Thanks so much for your help. I will for sure take your suggestions on board and have a look at how i am doing things. Thanks again Barand, i will take yours on board also. How would i go about this without having two sets of code? Would i have another document with an include?
  9. I have just realised, that i dont have job id in that query. I need to only select items that have the job id that has been set. In the current case, i only have one job id in the table but i dont use this variable in the second query $jid = $_SESSION[current_job_id]
  10. Just as an fyi, when i run this in mysql this is what i see. I changed the ? in the query to be 1.
  11. Table A - ssm_menu This is where the menu name and price are defined menu_id menu_name menu_price 1 menu 1 22.50 2 menu 2 51.50 Table B - ssm_menu_connection This is where the menu items are connected to a menu menu_id menu_item_id surrogate_id 1 1 1 1 4 2 2 1 3 Table C - ssm_menu_item This is where the individual items for each menu are defined and given a catagory menu_item_id menu_item_name menu_item_catagory 1 soup starter 2 pudding desert Table D - ssm_menu_order When the menu items are given a qantity, this is the table that they go into for later use. job_id menu_id menu_item_id menu_item_qty surrogate_id 1 1 1 100 1 1 1 2 100 2 This is the basic layout of all of the tables that are used in the query. If the user selects menu one and submits the form with quantities for some of the items, when the page reloads i want it to display all items in the menu that the user select but also show the quantities that they submitted. This will mean that some items have quantities and some do not. Either way all menu items for that menu should be shown. I hope this helps. Kind Regards
  12. Hi all, I am pulling info from my database but for some reason the results are being populated twice. The code i have is below: $jid = $_SESSION['current_job_id']; $sql = "SELECT * FROM ssm_menu_order where job_id = $jid"; $result = mysqli_query($conn, $sql); if(mysqli_num_rows($result)>0){ $sql = "SELECT menu_name, menu_price, menu_item_name, menu_item_catagory, b.menu_item_id, a.menu_id, d.job_id, d.menu_item_qty FROM ssm_menu a INNER JOIN ssm_menu_connection b on a.menu_id = b.menu_id INNER JOIN ssm_menu_items c on b.menu_item_id = c.menu_item_id left join ssm_menu_order d on c.menu_item_id = d.menu_item_id WHERE d.menu_id = ? ORDER BY (CASE c.menu_item_catagory WHEN 'Starter' THEN 1 WHEN 'Main' THEN 2 WHEN 'Dessert' THEN 3 ELSE 100 END) ASC, c.menu_item_name ASC"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $_GET['q']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($mname, $mprice, $mitname, $mitcat, $miid, $mid, $jid, $qty); echo"<form action='actions/update-menu-action.php' method='post'>"; echo "<button type='submit' name='select_menu_update_button' class='btn btn-primary float-right mb-2'>Update</button>"; echo "<table class='table table-striped table-hover table-bordered mt-3'>"; $first = true; while($stmt->fetch()){ if($first) { echo "<tr>"; echo "<th class='text-center' colspan='5'><div>".$mname." - £".$mprice."</div></th>"; echo "</tr>"; echo "<tr class='text-center'><th>Course</th><th>Dish</th><th>Notes</th><th>Quantity</th></tr>"; $first = NULL; } echo "<tr>"; echo "<td class=''>" . $mitcat . "</td>"; echo "<td class=''>" . $mitname . "</td>"; echo "<td><input type='text' /></td>"; echo "<input type='hidden' name='menuItemId[]' value='".$miid."'>"; echo "<input name='menuId' type='hidden' value='".$mid."'/>"; echo "<td><input class='text-center' name='menuItemQty[]' value='".$qty."' /></td>"; echo "</tr>"; } echo "</table>"; echo "</form>"; $stmt->close(); } else { $sql = "SELECT menu_name, menu_price, menu_item_name, menu_item_catagory, b.menu_item_id, a.menu_id FROM ssm_menu a INNER JOIN ssm_menu_connection b on a.menu_id = b.menu_id INNER JOIN ssm_menu_items c on b.menu_item_id = c.menu_item_id WHERE a.menu_id = ? ORDER BY (CASE c.menu_item_catagory WHEN 'Starter' THEN 1 WHEN 'Main' THEN 2 WHEN 'Dessert' THEN 3 ELSE 100 END) ASC, c.menu_item_name ASC"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $_GET['q']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($mname, $mprice, $mitname, $mitcat, $miid, $mid); echo"<form action='actions/submit-menu-action.php' method='post'>"; echo "<button type='submit' name='select_menu_submit_button' class='btn btn-primary float-right mb-2'>Submit</button>"; echo "<table class='table table-striped table-hover table-bordered mt-3'>"; $first = true; while($stmt->fetch()){ if($first) { echo "<tr>"; echo "<th class='text-center' colspan='5'><div>".$mname." - £".$mprice."</div></th>"; echo "</tr>"; echo "<tr class='text-center'><th>Course</th><th>Dish</th><th>Notes</th><th>Quantity</th></tr>"; $first = NULL; } echo "<tr>"; echo "<td class=''>" . $mitcat . "</td>"; echo "<td class=''>" . $mitname . "</td>"; echo "<td><input type='text' /></td>"; echo "<input type='hidden' name='menuItemId[]' value='".$miid."'>"; echo "<input name='menuId' type='hidden' value='".$mid."'/>"; echo "<td><input name='menuItemQty[]' /></td>"; echo "</tr>"; } echo "</table>"; echo "</form>"; $stmt->close(); } For some reason, the reasults are being echo'd twice.
  13. Ok tested and that did the trick. Thanks for all of your help. I didnt even know that was a thing. Kind Regards Adam
  14. Ok, so if i follow you correctly, i have run the follwing on my table ALTER TABLE `ssm_equipment_order` ADD UNIQUE( `job_id`, `equipment_id`); Is this what you were referring to?
×
×
  • 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.