Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I could not see any value in using a join. You would need either two queries or conditional statements as now. I created a table with 1000 rows of random values and nulls and ran your query. I also ran your query a second time on the same data with an added "WHERE col_1 IS NULL OR col_2 is NULL". Here are the the two run times 0.05800 0.02900
  2. Might have been officially deprecated in 5.3 but warnings against their use were around over 10 years ago
  3. Try using "AND" instead of "||"
  4. If you get your tail command to write the selected lines to a file, say "log.txt" for example Wed Oct 29 18:35:25 MDT 2014 1001 : ERROR -- speh1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-102 Thu Oct 30 18:35:25 MDT 2014 1201 : WARNING -- abcd1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-103 Fri Oct 31 18:35:25 MDT 2014 1302 : NOTICE -- mamc1 WEBFETAL PROBLEM: fetal-sa-triage is NOT RUNNING-104 Then the processing would look like this <?php function split_row($str) { $date = substr($str,0,28); $str = substr($str,29); $arr = explode(' -- ', $str); $err = $arr[0]; $words = explode(' ', $arr[1]); $code = array_shift($words); $msg = join(' ', $words); return "<tr><td>$date</td><td>$code</td><td>$msg</td><td>$err</td></tr>\n"; } $lines = file('log.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $logdata = ''; foreach ($lines as $line) { $logdata .= split_row($line); } ?> <html> <head> <title>Log sample</title> </head> <body> <table border='1' cellpadding='3'> <tr><th>Date</th><th>Code</th><th>Message</th><th>Error</th></tr> <?=$logdata?> </table> </body> </html>
  5. Have you considered something like the calc() function in the second user note at http://php.net/manual/en/function.eval.php?
  6. http://php.net/manual/en/features.file-upload.multiple.php
  7. If, as I suggested in reply #7, your data is stored in an array the data will not be lost. Only data in any unsaved result sets will be lost when the connection closes. There is no problem with two connections. I have done it many times when I needed to connect to a development and production server in the same script or when a script required connections to MySql server and an MS SQL server
  8. Rather than have a loop running the inserts a multiple insert would be fare more efficient, eg INSERT INTO table2 (username) VALUES ('CosmonautBob'), ('ooglebrain'),('JamieKG'),('Quinnter16') So your code would be $names = array(); while($row = mysqli_fetch_assoc($result)) { $name = $row['username']; $names[] = "('$name')"; } $conn->close(); //// now connect to the second server $conn2 = new mysqli(HOST2,USERNAME,PASSWORD,DATABASE); $sql = "INSERT INTO table2 (username) VALUES\n" . join(',', $names); $conn2->query($sql);
  9. Store the data in an array then connect to the second server and write the data
  10. What does the prices array contain at this point in the code? var_export($prices);
  11. With a single line of code without context, and no knowledge of the contents of the variables, all we can do is play guessing games.
  12. Revision with reset button <html> <head> <title>Sample</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+chosen+"]").hide(); } }) }) $("#btnReset").click(function() { $("option").show(); this.form.reset(); }) }) </script> </head> <body> <form> <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> <input type='button' name='btnReset' id='btnReset' value='Reset'> </form> </body> </html>
  13. Here's a sample script using the above. PHP creates the dropdowns and sends the page to the browser. Once the page is open in the browser the JS checks for changes in the selections and updates the other dropdowns. sample.php <html> <head> <title>Sample</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+chosen+"]").hide(); } }) }) }) </script> </head> <body> <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> </body> </html>
  14. Are the values in col1 and col2 always the same, unless NULL, or is that just a coincidence in your sample data? If they will become identical you only need to update null values in col1, as col2 will become redundant after the update. UPDATE jazz SET col1 = col2 WHERE col1 IS NULL; Now you can drop col2.
  15. I find it easier to use divs with a float:left and width ~30% of the enclosing area.
  16. Are the two databases on the same server? If they are then you still access them both in a single query.
  17. You don't AJAX, just javascript Create dropdowns <?php for ($i=0; $i<5; $i++) { echo "<select class='sel' id='sel$i' name='sel$i'> <option value=''>---</option>"; for ($j=1; $j<=5; $j++) { echo "<option value='$j'>$j</option>"; } echo "</select> "; } ?> and the script <script type="text/javascript"> $().ready(function() { $(".sel").change(function() { var curID = $(this).attr("id"); var chosen = $(this).val(); $(".sel").each(function(i,v) { if (v.id != curID) { $(v).children("option[value="+chosen+"]").hide(); } }) }) }) </script>
  18. Alternatively $str = "be33cfc1f0eed02e8176d7281975b05e"; $k = strlen($str); $x = unpack('c*', $str); echo '<pre>'; for ($i=1; $i<$k+1; $i++) { printf('| %2d | %02X | %1c |<br>', $i, $x[$i], $x[$i]); } echo '</pre>'; Giving | 1 | FFFFFFEF | ï | | 2 | FFFFFFBB | » | | 3 | FFFFFFBF | ¿ | | 4 | FFFFFFEF | ï | | 5 | FFFFFFBB | » | | 6 | FFFFFFBF | ¿ | | 7 | FFFFFFEF | ï | | 8 | FFFFFFBB | » | | 9 | FFFFFFBF | ¿ | | 10 | 62 | b | | 11 | 65 | e | | 12 | 33 | 3 | | 13 | 33 | 3 | | 14 | 63 | c | | 15 | 66 | f | | 16 | 63 | c | | 17 | 31 | 1 | | 18 | 66 | f | | 19 | 30 | 0 | | 20 | 65 | e | | 21 | 65 | e | | 22 | 64 | d | | 23 | 30 | 0 | | 24 | 32 | 2 | | 25 | 65 | e | | 26 | 38 | 8 | | 27 | 31 | 1 | | 28 | 37 | 7 | | 29 | 36 | 6 | | 30 | 64 | d | | 31 | 37 | 7 | | 32 | 32 | 2 | | 33 | 38 | 8 | | 34 | 31 | 1 | | 35 | 39 | 9 | | 36 | 37 | 7 | | 37 | 35 | 5 | | 38 | 62 | b | | 39 | 30 | 0 | | 40 | 35 | 5 | | 41 | 65 | e |
  19. You clearly have a centered column on the left side of your image. Can you not see how that was achieved and apply it to the other items?
  20. There seems to be 9 chars before the first "b" with these hex codes 0 - 0xEF 1 - 0xBB 2 - 0xBF 3 - 0xEF 4 - 0xBB 5 - 0xBF 6 - 0xEF 7 - 0xBB 8 - 0xBF // copy/pasted first string $str = "be33cfc1f0eed02e8176d7281975b05e"; $k = strlen($str); echo '<pre>'; for ($i=0; $i<$k; $i++) { printf('%2d 0x%2s %1s<br>', $i, dechex(ord($str[$i])), $str[$i]); }
  21. This will break down the line for you (assuming they all have the same basic format) function split_row($str) { $date = substr($str,0,28); $str = substr($str,29); $arr = explode(' -- ', $str); $err = $arr[0]; $words = explode(' ', $arr[1]); $code = array_shift($words); $msg = join(' ', $words); return "<tr><td>$date</td><td>$code</td><td>$msg</td><td>$err</td></tr>"; }
  22. Why don't you get the total when you query the table? SELECT a.OperatorID , u.OperatorName , u.MonthlyGoal , SUM(a.ChargeAmount) as total FROM tblUserPayments a LEFT JOIN tblOperatorGoals u ON a.OperatorID = u.OperatorID AND u.MonthlyGoal LIKE '$currentDate%' WHERE a.ChargeAmount IS NOT NULL AND a.PaymentStatus='OK' AND a.PaymentDate LIKE '$currentDate%' GROUP BY a.OperatorID " );
  23. Here's how, but you will have to do the TWIG bits <?php include("db_inc.php"); // defines credentials $db = new mysqli(HOST,USERNAME,PASSWORD,'bogdaniel'); // GET THE ROLES TO USE AS HEADINGS $sql = "SELECT RoleId, RoleName FROM tbl_user_roles ORDER BY RoleId"; $res = $db->query($sql); $roles = array(); while (list($rid, $rnm) = $res->fetch_row()) { $roles[$rid] = $rnm; } $theads = "<tr><th>Permission</th><th>".join('</th><th>',$roles)."</th></tr>\n"; $tdata = ''; // CREATE A DEFAULT ARRAY TO STORE THE ROLE VALUES FOR EACH PERMISSION // THIS WILL BE UPDATED AND OUTPUT WHEN THE PERMISSION CHANGES $default = array_fill_keys(array_keys($roles), 'x'); // NOW WE CAN GET THE DATA FOR THE TABLE $sql = "SELECT t3.PermissionName, t2.RoleId FROM tbl_user_role_perm AS t1 INNER JOIN tbl_user_roles AS t2 ON t1.RoleId = t2.RoleId INNER JOIN tbl_user_permissions AS t3 ON t1.PermissionId = t3.PermissionId ORDER BY t1.PermissionId, t2.RoleId"; $res = $db->query($sql); $permArray = $default; $currPerm = ''; while (list($perm, $rid) = $res->fetch_row()) { if ($perm != $currPerm) { // change of permission? if ($currPerm != '') { $tdata .= "<tr><td class='perm'>$currPerm</td><td>" . join ('</td><td>', $permArray) . "</td></tr>\n"; } $currPerm = $perm; // reset for next permission $permArray = $default; } $permArray[$rid] = '&check;'; // update if perm/role exists } // DO NOT FORGET THE FINAL PERMISSION $tdata .= "<tr><td class='perm'>$currPerm</td><td>" . join ('</td><td>', $permArray) . "</td></tr>\n"; ?> <html> <head> <title>Sample</title> <meta name="author" content="Barand"> <meta name="creation-date" content="10/31/2014"> <style type="text/css"> table { border-collapse: collapse; } th { width: 70px; background-color: #ccc; font-family: sans-serif; font-size: 8pt; } td { font-family: sans-serif; font-size: 12pt; text-align: center; } td.perm { font-size: 8pt; text-align: left; width: 150px; } </style> </head> <body> <table border='1'> <?=$theads?> <?=$tdata?> </table> </body> </html> Gives:
  24. If they are already in a table then you won't need to create another. But then I have no idea of what you are starting with so an example would be impossible.
  25. Put the ones that you want to check into a temporary table and use a LEFT JOIN to check for missing ids
×
×
  • 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.