Jump to content

Barand

Moderators
  • Posts

    24,353
  • Joined

  • Last visited

  • Days Won

    797

Everything posted by Barand

  1. It sounds like it would be more efficient to make [#][0] the key of sets of subarrays . Then you can go straight ot the ones you want instead of repeatedly searching the whole array. array ( [string] => array ( array (int, int, string, string), array (int, int, string, string), array (int, int, string, string), array (int, int, string, string) ), ... [string] => array ( array (int, int, string, string), array (int, int, string, string), array (int, int, string, string), array (int, int, string, string) ) );
  2. Protecting a form field from what? htmlspecialchars() is for use when outputting user-supplied data data to a web page. mysql_real_escape string() is was used to protect input values to queries from SQL injection. This is now obsolete, replaced by mysqli_real_escape_string() or (better still) the use of prepared statements to completely separate the query code from the user-supplied data.
  3. Barand

    phpdoc not work

    Then your first stop should have been the forum rules
  4. Barand

    phpdoc not work

    So far you have posted this, or similar, in the Linux, Miscellaneous and PHP Coding forums. Stop spreading it all over the site - just append comments to your original topic (Linux forum) Moving this post.
  5. With an array of data like the one you described $projects = [ [ 'job_no' => '101', 'job_name' => 'Job 101', 'job_due' => '2019-08-15' ], [ 'job_no' => '102', 'job_name' => 'Job 102', 'job_due' => '2019-07-31' ], [ 'job_no' => '103', 'job_name' => 'Job 103', 'job_due' => '2019-08-31' ], [ 'job_no' => '104', 'job_name' => 'Job 104', 'job_due' => '2019-07-29' ], [ 'job_no' => '105', 'job_name' => 'Job 105', 'job_due' => '2019-08-15' ] ]; First sort the array with a custom sort function comparing the due dates usort($projects, function($a,$b) { return $a['job_due'] <=> $b['job_due']; } ); then you can loop through the array elements outputting each in its own row echo "<table style='width:500px;' > <tr> <td>Job No</td><td>Name</td><td>Date Due</td> </tr>\n"; foreach ($projects as $proj) { $formatted = date('d/m/Y', strtotime($proj['job_due'])); echo "<tr><td>{$proj['job_no']}</td><td>{$proj['job_name']}</td><td>$formatted</td></tr>\n"; } echo "</table>\n";
  6. Your form method is post, so the variables will be in $_POST array. As stated, your query needs to be inside double quotes to interpolate the variables. Don't run queries in loops, especially when one which correctly uses "IN()" will do the job. Don't rely on button values being POSTed (browser dependent) if ($_SERVER['REQUEST_METHOD']=='POST') { //data removal code will be going here $kuemid = array_map('intval',$_POST['kuemid']); // ensure all ids are integers $del_id = join(',', $kuemid); // put ids in a comma separated string $wpdb->query( "DELETE FROM '.$wpdb->prefix.'kudos_email WHERE kuemid IN($del_id)" ); // etc }
  7. Another simple method is to add a version number column to the table ... CREATE TABLE `test_product` ( `prod_id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(50) DEFAULT NULL, `price` decimal(10,2) DEFAULT NULL, `version` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`prod_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; mysql> select * from test_product; +---------+-------------+-------+---------+ | prod_id | description | price | version | +---------+-------------+-------+---------+ | 1 | Product A | 49.99 | 2 | +---------+-------------+-------+---------+ ... then, when updating, make sure the record still has the same version number that you retrieved. If the number is the same you can update and increment the version. Below is a sample page which demonstrates this. Open in two browser pages - both will show the same data change one field in the first page and update then go to second page and change second field and update <?php include 'db_inc.php'; // Substitute your own $db = pdoConnect('test'); // database connection code if ($_SERVER['REQUEST_METHOD']=='POST') { $stmt = $db->prepare("UPDATE test_product SET description = ?, price = ?, version = version+1 WHERE prod_id = 1 AND version = ? "); $stmt->execute([ $_POST['descrip'], $_POST['price'], $_POST['version'] ] ); if ($stmt->rowCount()==0) { // update didn't happen echo "Concurrent update occurred, try again<br>" ; } } $res = $db->query("SELECT description , price , version FROM test_product WHERE prod_id = 1 "); $r = $res->fetch(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> </script> <style type="text/css"> </style> </head> <body> <form method="POST"> <input type="text" name="descrip" value="<?=$r['description']?>"><br> <input type="text" name="price" value="<?=$r['price']?>"><br> <input type="hidden" name="version" value="<?=$r['version']?>"><br> <!-- hidden field --> <input type="submit" name="btnSub" value="Submit"> </form> </body> </html>
  8. You evidently missed this "main line" code when you read the initial post.... <ul class="navbar-nav mr-auto"> <?=menu_builder1($db, 0)?> </ul>
  9. 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.
  10. 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>
  11. 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.
  12. Describe to yourself (or someone else if that helps) what the last two lines of code are doing.
  13. 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>
  14. Look more carefully at the examples on that manual page
  15. 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
  16. I would have to say "yes" to that. Give your inputs class names or ids and use css definitions
  17. 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>
  18. 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>'); } });
  19. 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)
  20. $('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>'); } });
  21. You might want to look at SVG gradients and SVG graphics in general.
  22. Store the info that the user put in the original QR code. User retrieves and edits the data, then generates new QR code.
  23. As gradients come in two flavours - linear and radial, then good luck with that.
×
×
  • 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.