Jump to content

Barand

Moderators
  • Content Count

    19,407
  • Joined

  • Last visited

  • Days Won

    383

Barand last won the day on July 17

Barand had the most liked content!

Community Reputation

1,310 Excellent

3 Followers

About Barand

  • Rank
    Sen . ( ile || sei )

Profile Information

Recent Profile Visitors

57,698 profile views
  1. FYI - if you had bothered to answer my question last Monday we could have sorted your problem days ago. I take the view that if you won''t spare a couple of minutes to answer my question, why should I give up my time to answer yours? Also you have totally ignored the advice given by @mac_gyver on how to tackle the problem correctly, so I am guessing he's now one of this site's experts that will think twice before assisting you next time.
  2. Put your PHP code before the HTML code in your scripts. Then things like $title can be given a value before you output them
  3. I would use class names instead id names. It simplifies iteration. I would also use the money_id as the index in the input fieldname for the qty. $result = [ ['money_id' => 1, 'money_item' =>'Item A', 'money_value' => 300, 'money_qty' => 10 ], ['money_id' => 2, 'money_item' =>'Item B', 'money_value' => 500, 'money_qty' => 10 ], ['money_id' => 3, 'money_item' =>'Item C', 'money_value' => 1000, 'money_qty' => 10 ], ['money_id' => 4, 'money_item' =>'Item D', 'money_value' => 1500, 'money_qty' => 10 ], ['money_id' => 5, 'money_item' =>'Item E', 'money_value' => 2000, 'money_qty' => 10 ] ]; echo "<table>"; foreach ($result as $row){ $mid = $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='$mid' ></td>"; echo "<td class='text-center'><input class='Qty up text-center' value='{$row['money_qty']}' name='moneyQty[$mid]' type='text' data-id='$mid' ></td>"; echo "<td><span class='moneyTotal' data-id='$mid' >Total</span></td>"; echo "</tr>\n"; } echo "<tr><td colspan='2'>Total</td><td id='grandtotal'>Grand Total</td></tr>\n"; echo "</table>\n" When you process the POSTed data you can then just foreach ($_POST['moneyQty'] as $mid => $moneyQty) { // now you have the id to retrieve price from database // as you process each quantity } Javascript <script type="text/javascript"> $().ready( function() { calcLineTotals() $(".Qty").change( function() { calcLineTotals() }) }) function calcLineTotals() { var gtot = 0 $(".Qty").each( function(k,v) { // foreach element of class "Qty" var mid = $(v).data("id") // get its data-id var qty = $(v).val() // get the qty var price = $(".moneyValue[data-id="+mid+"]").val() // get price from moneyValue element with same data-id $(".moneyTotal[data-id="+mid+"]").html(qty * price) // put total in total element with same data-id gtot += qty* price // accumulate grand total }) $("#grandtotal").html(gtot) // put grand total in element with id = grandtotal } </script>
  4. A couple of comments Why do you want to mutiply the amount by the amount? If you are sending those amounts to your server, ignore them. Requery your database for the price values based on the product ids (which you should be sending along with the quantities. (If you use prices sent by the user you could end up selling everything for 0.01). By all means show the total values, but purely for customer convenience.
  5. That's two out of the three. Ensure your connection to the DB sever is also utf8 EG $db = new PDO("mysql:host=".HOST.";dbname=".DATABASE.";charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  6. Looks to me like invalid XML - missing a "<" tag opene.r
  7. On the line before the "unset" ... if (array_key_exists($_POST['delete'], $_SESSION['playlist']) { ... count the number of opening parentheses "(" and count the number of closing ones. (That should show you why the "unset" is unexpected)
  8. But $test = $interval->format('%m'); was your example. Are you claiming that isn't OO?
  9. Not sure what you are trying to say with that comment. How would you use date intervals without "the OO method of coding"?
  10. Note that instead of using the format method to get the months value ... $test = $interval->format('%m'); you can get it directly from the "m" property of the interval object... $test = $interval->m; Similarly, you can use the ->days property instead of ->format('%a')
  11. As the error message says" ... expects 1 parameter". You haven't provided any in ... or die( mysqli_error() ); RTFM
  12. Immedialtely after posting my first reply I realised I hadn't posted my results. I therefore edited the reply and added them. But they aren't there! Anyway, they were 2019-07-15 12:30:00 | 2019-07-17 14:15:30 | 0 0 2 1 45 30 2019-08-15 00:00:00 | 2019-08-17 01:45:30 | 0 0 2 1 45 30
  13. That could account for a one hour difference, but a whole day!?
  14. When I do this I get exactly the same differences??? function test2 ($start, $end, $newstart) { $dt1 = new DateTime($start); $dt2 = new DateTime($end); $dif = $dt1->diff($dt2); $dt3 = new DateTime($newstart); $dt4 = clone $dt3; $dt4->add($dif); echo $dt1->format('Y-m-d H:i:s') . ' | ' ; echo $dt2->format('Y-m-d H:i:s') . ' | ' ; echo $dif->format('%y %m %d %h %i %s') . '<br>' ; echo $dt3->format('Y-m-d H:i:s') . ' | ' ; echo $dt4->format('Y-m-d H:i:s') . ' | ' ; echo $dt3->diff($dt4)->format('%y %m %d %h %i %s') . '<br>' ; } test2('2019-07-15 12:30:00', '2019-07-17 14:15:30', '2019-08-15');
  15. Apply the mthod in my previous post
×
×
  • 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.