Jump to content
Pardon our ads (a necessary update) ×

bambinou1980

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by bambinou1980

  1. Mac Gyver, I have no words for your comments and will have to change my username as I don't like when someone is following me on the internet. "between the forums that i know you post on, you have several hundred posts"<---- NSA?
  2. Hello, I am not understanding why, I do not get an array output there, is there a problem with my php code? <?php $query = "SELECT o.orders_id, date_format(o.due_date, '%d/%m/%Y') as day, o.customer_paid, p.product_price, p.product_quantity, p.product_price * p.product_quantity AS totals, p.orders_orders_id FROM orders AS o LEFT JOIN products_ordered AS p ON o.orders_id = p.orders_orders_id WHERE YEAR(o.due_date) = YEAR(CURDATE()) AND MONTH(o.due_date) = MONTH(CURDATE()) WHERE o.customer_paid = 'PAID' GROUP BY o.orders_id"; if (mysqli_connect_errno()) die('Could not connect: ' . mysql_error()); $return_arr = array(); if ($result = mysqli_query($connection, $query)) { while ($row = mysqli_fetch_assoc($result)) { $row_array['orders_id'] = $row['orders_id']; $row_array['product_price'] = $row['product_price']; array_push($return_arr, $row_array); } } mysqli_close($connection); echo json_encode($return_arr); ?> Thanks
  3. Ok Worked it out: <?php while ($row = mysqli_fetch_array($result1, MYSQLI_ASSOC)) { $product_name = $row["product_name"]; $product_quantity = $row["product_quantity"]; $product_price = $row["product_price"]; $product_vat = $row["product_vat"]; ?><tr><td><div class="text-center"><h4><?php echo $product_name; ?></h4></div></td><td><div class="text-center"><h4><?php echo $product_quantity; ?></h4></div></td><td><div class="text-center"><h4><?php echo $product_price; ?></h4></div></td><td><div class="text-center"><h4><?php echo $product_vat; ?></h4></div></td></tr><?php } ?>
  4. Hello, I am trying to construct my first while loop and struggle a bit. I have a table with 4 columns, all I am trying to do is passing the product name, qty, price and vat in each column from the same table but cannot work out how to use only 1 loop rather than 4 because the html is on the way.... Any idea how I could compress the lot to make it only in 1 loop please? <?php $query1 = "SELECTo.orders_id,p.product_name,p.idFROM orders AS oLEFT JOIN products_ordered AS p ON o.orders_id = p.orders_orders_id WHERE o.orders_id = {$order_id}ORDER BY p.id DESC"; $result1 = mysqli_query($connection, $query1); if($result1 && mysqli_affected_rows($connection) < 1) { // Failure // $message = "Subject update failed"; die("Database query 1 failed. " . mysqli_error($connection));}?> <?php $query2 = "SELECTo.orders_id,p.product_quantity,p.idFROM orders AS oLEFT JOIN products_ordered AS p ON o.orders_id = p.orders_orders_id WHERE o.orders_id = {$order_id}ORDER BY p.id DESC"; $result2 = mysqli_query($connection, $query2); if($result2 && mysqli_affected_rows($connection) < 1) { // Failure // $message = "Subject update failed"; die("Database query 2 failed. " . mysqli_error($connection));}?> <?php $query3 = "SELECTo.orders_id,p.product_price,p.idFROM orders AS oLEFT JOIN products_ordered AS p ON o.orders_id = p.orders_orders_id WHERE o.orders_id = {$order_id}ORDER BY p.id DESC"; $result3 = mysqli_query($connection, $query3); if($result3 && mysqli_affected_rows($connection) < 1) { // Failure // $message = "Subject update failed"; die("Database query 3 failed. " . mysqli_error($connection));}?> <?php $query4 = "SELECTo.orders_id,p.product_vat,p.idFROM orders AS oLEFT JOIN products_ordered AS p ON o.orders_id = p.orders_orders_id WHERE o.orders_id = {$order_id}ORDER BY p.id DESC"; $result4 = mysqli_query($connection, $query4); if($result4 && mysqli_affected_rows($connection) < 1) { // Failure // $message = "Subject update failed"; die("Database query 4 failed. " . mysqli_error($connection));}?> <!-- / end client details section --> <table class="table table-bordered"> <thead> <tr> <th> <h4 class="text-center">Products Ordered</h4> </th> <th> <h4 class="text-center">Qty</h4> </th> <th> <h4 class="text-center">Products Prices</h4> </th> <th> <h4 class="text-center">V.A.T</h4> </th> </tr> </thead> <tbody> <tr> <td><div class="text-center"><h4> <?php while ($row = mysqli_fetch_array($result1, MYSQLI_ASSOC)) { $product_name = $row["product_name"]; echo $product_name . '<br>';} ?> </h4></div></td> <td><div class="text-center"><h4> <?php while ($row = mysqli_fetch_array($result2, MYSQLI_ASSOC)) { $product_quantity = $row["product_quantity"]; echo $product_quantity . '<br>';} ?> </h4></div></td> <td><div class="text-center"><h4> <?php while ($row = mysqli_fetch_array($result3, MYSQLI_ASSOC)) { $product_price = $row["product_price"]; echo "€" .$product_price . '<br>';} ?> </h4></div></td> <td><div class="text-center"><h4> <?php while ($row = mysqli_fetch_array($result4, MYSQLI_ASSOC)) { $product_vat = $row["product_vat"]; echo $product_vat . '%<br>';} ?> </h4></div></td> </tr> </tbody> </table>
  5. Hi Mac_gyver. Ok let me explain further. My problem is those 2 input fields not changing their values according to the loop data() values: <input type="text" name="products_id[]" class="id1"/> <input type="text" name="vat[]" class="vat1"/>
  6. Yes this is exactly what I am experiencing "all the select/option menus to the same set of prices, and resetting already selected prices". I can work out the arrays in PHP and submit the data in a loop but with Javascript I am not understanding how to get the same effect. Specifically this part: $(this).closest('.form-group').find('.form-control.prices1').html(options); How to get all the ids to increment in number(if this is the answer to the problem). I would have preferred something like in PHP with prices[]. Kind of lost to be honest...
  7. Hello, I am having a problem with a php loop in which I just cannot get the data product to be shown when I add a new form element(identical). So imagine a form with an "add" and "delete" button, when I click "add" the dropdown button with "product name" is duplicated". My goal is to have the user adding multiple of those drop down buttons which when select cause different prices to be loaded. At the moment this works great for the first field but as soon as I add more than one, the price vat and product id are are loaded but based on the first dropdown each time. There is something in my javascript code that is not telling the browser to notice the incremental changes when we add the new buttons, any idea please? The product name and prices are changing right not but not the vat and product id. Here is the php: <!--Product 1--> <div id="element1" class="field"> <div class="form-inline well"> <label for="product1">Choose Product*</label> <div class="form-group" id="totals"> <select name="name[]" class="form-control products1"> <option>Select a Product</option> <?php $query_product1 = "SELECT * FROM products ORDER BY name desc"; $result_product1 = mysqli_query($connection, $query_product1) or die(mysqli_error()); while ($row_product1 = mysqli_fetch_array($result_product1)) { $product1_id = $row_product1['products_id']; $product1_name = $row_product1['name']; $product1_price1 = $row_product1['price1']; $product1_price2 = $row_product1['price2']; $product1_price3 = $row_product1['price3']; $product1_vat = $row_product1['vat']; ?> <option value="<?php echo $product1_name; ?>" data-product1_id="<?php echo $product1_id; ?>" data-product1_vat="<?php echo $product1_vat; ?>" data-product1_price1="<?php echo $product1_price1; ?>" data-product1_price2="<?php if ($product1_price2 != 0.00) { echo $product1_price2; } ?>" data-product1_price3="<?php if ($product1_price3 != 0.00) { echo $product1_price3; } ?>"><?php echo $product1_name; ?></option><?php } ?> </select> <input type="text" name="products_id[]" class="id1"/> <input type="text" name="vat[]" class="vat1"/> <select name="price[]" class="form-control prices1"> <option>Select Price</option> </select> <label for="product1_id">Qty</label> <input name="quantity[]" type="number" class="form-control quantity1" maxlength="8" size="4" required> <label for="total_id">Total Cost(€)</label> <input name="total1" type="text" class="form-control total1" value="0" maxlength="8" size="4" required> <button type="button" class="btn btn-warning">Calculate</button> </div> </div> </div> <!--Product 1--> JS $(function product1() { $('.form-control.products1').change(function () { var selected = $('option:selected', this); var options = '<option>Select Price</option>'; for (var i = 1; i <= 3; i++) { options += '<option>' + selected.data('product1_price' + i) + '</option>'; } $('.form-control.prices1').html(options); $(this).closest('.form-group').find('.id1').val(selected.data('product1_id')); $(this).closest('.form-group').find('.vat1').val(selected.data('product1_vat')); }); }); Thanks and Happy Xmas!
×
×
  • 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.