Jump to content

Barand

Moderators
  • Posts

    24,344
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. Is your dbname really "dbname"?. You might want to make some useful enhancements to your pdo connection code $db = new PDO("mysql:host=$servername;dbname=dbname", $username, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // error reporting auto handled $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // saves specifying every time $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // handle prepared queries correctly In the above query there are no parameters so, instead of prepare/execute, just use $db->query(); Just my 0.02 worth.
  2. There shouldn't be any need for timeout loops. In this example, my "certain criteria" is that an input must have an even value <form> <fieldset><legend>User Inputs</legend> A <input type="number" name="field_a" value="1" data-seq="1" class="my_input" autofocus><br> B <input type="number" name="field_b" value="3" data-seq="2" class="my_input" disabled><br> C <input type="number" name="field_c" value="5" data-seq="3" class="my_input" disabled><br> </fieldset> <br> <input type="submit" name="btnSubmit" value="Submit"> </form> JS code <script type="text/javascript"> $().ready( function() { $(".my_input").change( function() { var seq = $(this).data("seq") // ensure input is even and non-zero if ($(this).val() > 0 && $(this).val()%2==0) { ++seq var nextinput = $(".my_input[data-seq="+seq+"]") alert( $(nextinput).val() ) $(nextinput).prop("disabled",false) $(nextinput).focus() } else { $(this).focus() } }) }) </script>
  3. Consider this simple bit of form code <form method="POST"> <?php for ($id=1; $id<=3; $id++) { echo "<input type='text' name='aqty$id' value='0'>"; echo "<input type='text' name='bqty[$id]' value='0'><br>"; } echo "<input type='submit' name='btnSubmit' value='Submit'>"; ?> </form> The inputs "aqty"have the id concatenated to end of the name (as you have done) ie aty1, aqty2, aqty3 The "bqty" fields have names I had them "bqty[$id]". When the form is posted, the post data array looks like this Array ( [aqty1] => 10 [aqty2] => 20 [aqty3] => 30 [bqty] => Array ( [1] => 10 [2] => 20 [3] => 30 ) [btnSubmit] => Submit ) The "aqty" items are posted as 3 separate variables ($_POST['aqty1'] ...$_POST['aqty3']) . The "bqty" items are posted in an array where the keys are the id values. This enables me to use the foreach ($_POST['bqty'] as $id => $qty) to loop through all the posted values EDIT: In my example the ids are seqential so you can process your method with a simple for() loop. However, in the real world where the data has come from a query, the ids are effectively random so that method cannot be used ( EG ids are 13, 17, 129 ). My method would work with all id values.
  4. Describe to yourself (or someone else if that helps) what the last two lines of code are doing.
  5. How about <script type="text/javascript"> $( document ).ready(function(){ ccmatrix = $("#ccMatrix"); var form = $("<form/>", {action: '#',method: '#'}); for(i=0; i<3; i++) { for(j=0; j<3; j++) { cname = "col"+j // class name for each column $(ccmatrix).append($("<input/>", { type: 'text', class: 'result ' + cname, name: 'u_i', tabindex: j*3+i, value: j*3+i, autofocus: j+i==0 })); } $(ccmatrix).append('<br>'); } }); </script> <style type="text/css"> .col0 { background-color: #ff11aa;} .col1 { background-color: #aaff11;} .col2 { background-color: #11aaff;} .result {text-align: right; width: 50px; padding: 4px; margin: 8px } </style>
  6. Look more carefully at the examples on that manual page
  7. You have to fetch the row from your result set that the query returned https://www.php.net/manual/en/mysqli-result.fetch-assoc.php
  8. I would have to say "yes" to that. Give your inputs class names or ids and use css definitions
  9. try <script type="text/javascript"> var colors = [ 'red', 'green', 'blue', 'yellow', 'cyan', 'magenta', 'orange', 'coral', 'khaki' ] $( document ).ready(function(){ ccmatrix = $("#ccMatrix"); var form = $("<form/>", {action: '#',method: '#'}); counter = 0; for(i=0; i<3; i++) { for(j=0; j<3; j++) { var clr = colors[j*3+i] $(ccmatrix).append($("<input/>", { type: 'text', id: 'result', name: 'u_i', size: '1px', tabindex: j*3+i+1, autofocus: ( j*3+i+1==5 ), // set focus on 5th when page loads style: 'background-color:'+clr+'; color:white; text-align:right; font-weight:600' })) } $(ccmatrix).append('<br>'); } }); </script>
  10. Using my original code with the addition of "tabindex" attributes to control the input order ... $( document ).ready(function(){ ccmatrix = $("#ccMatrix"); var form = $("<form/>", {action: '#',method: '#'}); counter = 0; for(i=0; i<3; i++) { if(i===0) clr = '#ff11aa'; if(i===1) clr = '#aaff11'; if(i===2) clr = '#11aaff'; for(j=0; j<3; j++) { $(ccmatrix).append($("<input/>", { type: 'text', id: 'result', name: 'u_i', size: '1px', tabindex: j*3+i+1, style: 'background-color:'+clr })) } $(ccmatrix).append('<br>'); } });
  11. Treat the QR code like you would treat an address label. You print the label from the data in your database. If the address changes you change it in the database and reprint the label. You do not attempt to scan the exisiting label with an OCR reader in order to alter the address (or perhaps you do)
  12. $('input').css({backgroundColor: '#aaff11'}); means set all "input"s to this background color - so they all get the same value on each call. try $( document ).ready(function(){ ccmatrix = $("#ccMatrix"); var form = $("<form/>", {action: '#',method: '#'}); counter = 0; for(i=0; i<3; i++) { if(i===0) clr = '#ff11aa'; if(i===1) clr = '#aaff11'; if(i===2) clr = '#11aaff'; for(j=0; j<3; j++) { $(ccmatrix).append($("<input/>", { type: 'text', id: 'result', name: 'u_i', size: '1px', value: j*3+i+1, style: 'background-color:'+clr })) } $(ccmatrix).append('<br>'); } });
  13. You might want to look at SVG gradients and SVG graphics in general.
  14. Store the info that the user put in the original QR code. User retrieves and edits the data, then generates new QR code.
  15. As gradients come in two flavours - linear and radial, then good luck with that.
  16. What does your job_listing_class() function look like?
  17. You use the <?= ...?> synatx when inserting a PHP expression into your HTML. With your you are trying to insert into a string value within your PHP code so you would just concatenate the function output as shown in my "echo" example $output .= '<li><a href="' . get_term_link( $subterms ) . '" ' . job_listing_class() . '>' . $subterms->name; (assuming your function now returns the string value instead of echoing it)
  18. It would appear that your function is echoing the class and therefore it works in the first code EG function job_listing_class() { echo 'class="xyz"'; } In the second code you are concatenating the output from the function but there isn't any. In this case the function would need to return a string value EG function job_listing_class() { return 'class="xyz"'; } Then you can echo '<section id="title" ' . job_listing_class() . ' >'; or, in your HTML <section id="title" <?=job_listing_class()?> > EDIT: Generally, it is better for functions to return values.
  19. 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.
  20. Put your PHP code before the HTML code in your scripts. Then things like $title can be given a value before you output them
  21. 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>
  22. 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.
  23. 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);
  24. Looks to me like invalid XML - missing a "<" tag opene.r
×
×
  • 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.