Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. I think you should recheck your calculations +-------+----------+---------+----------+-------------------+-----------------+ | recno | user | v_score | reccount | last5 | av5 = last5/5 | my results your results +-------+----------+---------+----------+-------------------+-----------------+ | 3 | mina1111 | 2 | 1 | 2 | | | 6 | mina1111 | 4 | 2 | 2 + 4 | | | 7 | mina1111 | 3 | 3 | 2 + 4 + 3 | | | 8 | mina1111 | 2 | 4 | 2 + 4 + 3 + 2 | | | 9 | mina1111 | 4 | 5 | 2 + 4 + 3 + 2 + 4 | 15/5 = 3.0 | 3.0000 4.0000 | 10 | mina1111 | 5 | 6 | 4 + 3 + 2 + 4 + 5 | 18/5 = 3.6 | 3.6000 4.5000 | 11 | mina1111 | 0 | 7 | 3 + 2 + 4 + 5 + 0 | 14/5 = 2.8 | 2.8000 3.0000 | 12 | mina1111 | 1 | 8 | 2 + 4 + 5 + 0 + 1 | 12/5 = 2.4 | 2.4000 2.5000 | 13 | mina1111 | 1 | 9 | 4 + 5 + 0 + 1 + 1 | 11/5 = 2.2 | 2.2000 2.2000 +-------+----------+---------+----------+-------------------+-----------------+
  2. My solution requires just the records for mina1111 with consecutive record numbers (to facilitate finding the last 5 records) so I created a temporary table from your data. Also because I needed to reference the table a second time in a subquery (you can;t do this with temp tables) I had to create a second temporary table. I'm afraid it isn't the most efficient query ever written as it uses a dependent subquery. -- -- create temp table a -- create temporary table mina1111_a select a.recno , a.v_score , @count := @count+1 as reccount from ajoo a JOIN (select @count:=0) as init where user = 'mina1111'; -- -- create temp table b -- create temporary table mina1111_b select a.recno , a.v_score , @count := @count+1 as reccount from ajoo a JOIN (select @count:=0) as init where user = 'mina1111'; -- -- calculate rolling 5-record averages -- SELECT a.recno , j.user , a.v_score , a.reccount , ( SELECT AVG(b.v_score) as avscor FROM mina1111_b b WHERE reccount BETWEEN a.reccount-4 and a.reccount ) as av5 FROM mina1111_a a JOIN ajoo j using (recno) WHERE a.reccount > 4; -- -- remove the temporary tables -- drop temporary table mina1111_a; drop temporary table mina1111_b; results... +-------+----------+---------+----------+--------+ | recno | user | v_score | reccount | av5 | +-------+----------+---------+----------+--------+ | 9 | mina1111 | 4 | 5 | 3.0000 | | 10 | mina1111 | 5 | 6 | 3.6000 | | 11 | mina1111 | 0 | 7 | 2.8000 | | 12 | mina1111 | 1 | 8 | 2.4000 | | 13 | mina1111 | 1 | 9 | 2.2000 | +-------+----------+---------+----------+--------+ Temporary table... +-------+---------+----------+ | recno | v_score | reccount | +-------+---------+----------+ | 3 | 2 | 1 | | 6 | 4 | 2 | | 7 | 3 | 3 | | 8 | 2 | 4 | | 9 | 4 | 5 | | 10 | 5 | 6 | | 11 | 0 | 7 | | 12 | 1 | 8 | | 13 | 1 | 9 | +-------+---------+----------+
  3. This is my take on it. I copy/pasted a couple of extra jobs to give... CODE <?php $required = ['Feasibility', 'Measure Up', 'Model Drawing', 'Concept Design', 'Developed Design', 'Resource Consent', 'Construction Documentation' ]; $colors = array_combine($required, ['w3-red', 'w3-green', 'w3-orange', 'w3-deep-orange', 'w3-teal', 'w3-yellow', 'w3-purple'] ); $staff_arr = [ 'Staff1' => 'SP', 'Staff2' => 'MB', 'Staff3' => 'BF', 'Staff4' => 'MCP', 'Staff5' => 'DG' ]; function state_dropdown($staff, $color) { return "<form action='' method='POST'>" . "<select class='w3-input w3-round $color' name ='StaffName' onchange='this.form.submit()'>" . // why is a menu of states called "StaffName" ? "<option value =''>$staff</option>" . "<option class='form-control col-sm-3 bg-white text-dark'>Feasibility </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Measure Up </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Model Drawing </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Concept Design </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Developed Design </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Resource Consent </option> " . "<option class='form-control col-sm-3 bg-white text-dark'>Construction Docs </option> " . "</select>" . "</form>"; } $xml = simplexml_load_file('plugnz.xml'); $data = []; // // collect the jobs and current task data into an array // foreach ($xml->Jobs->Job as $job) { $id = (string)$job->ID; $state = (string)$job->State; if (!in_array($state, $required)) continue; $data[$id] = [ 'name' => (string)$job->Name, 'state' => $state ]; $tasks = $job->xpath("Tasks/Task[Name='$state']"); $clr = $colors[$state]; $due = (string)$tasks[0]->DueDate; $data[$id]['due'] = date('Y-m-d', strtotime($due)); $data[$id]['display_date'] = date('M d Y', strtotime($due)); $assigned = []; foreach ($tasks[0]->Assigned->Staff as $s) { $assigned[] = $staff_arr[(string)$s->Name]; } $staff_str = join(' ', $assigned); $data[$id]['task'] = [ 'staff' => $staff_str, 'clr' => $clr ]; } // // sort the data array on the task due date DESC // uasort($data, function($a,$b) { return $b['due'] <=> $a['due']; } ); // // output the array as a table // $tdata = ''; foreach ($data as $jid => $jdata) { $tdata .= "<tr><td class='jobno'>$jid</td><td>{$jdata['name']}</td>"; foreach ($required as $stat) { if ($jdata['state']==$stat) { $tdata .= "<td>" . state_dropdown($jdata['task']['staff'], $jdata['task']['clr']) . "</td>"; } else { $tdata .= "<td>&nbsp;</td>"; } } $tdata .= "<td>&nbsp;</td>"; $tdata .= "<td>{$jdata['display_date']}</td></tr>"; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="creation-date" content="05/10/2019"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <title>Job Status Table</title> <style type="text/css"> body { font-family: verdana,sans-serif; font-size: 10pt; padding: 20px 50px; } table {border-collapse: collapse;} .th-sm-1 { font-size: 8pt; text-align: left; } .jobno { font-weight: 600; color: #2196f3; } select { width: 120px; } </style> </head> <body> <table border=1> <thead> <tr> <th class="th-sm-1">Project Number</th> <th class="th-sm-1">Project Name</th> <th class="th-sm-1">Feasibility</th> <th class="th-sm-1">Measure Up</th> <th class="th-sm-1">Model Drawing</th> <th class="th-sm-1">Concept Design</th> <th class="th-sm-1">Developed Design</th> <th class="th-sm-1">Resource Consent</th> <th class="th-sm-1">Construction Docs</th> <th class="th-sm-1">Milestone</th> <th class="th-sm-1">Due Date</th> </tr> </thead> <tbody> <?=$tdata?> </tbody> </table> </body> </html>
  4. Given that xml extract $required = ['Feasibility', 'Measure Up', 'Model Drawing', 'Concept Design', 'Developed Design', 'Resource Consent', 'Construction Documentation' ]; $str = <<<XML <Jobs> <Job> <ID></ID> <Name>Job 1</Name> <State>Concept Design</State> <StartDate>2019-02-01</StartDate> <DueDate>2019-10-01</DueDate> <Tasks> <Task> <ID></ID> <Name>Measure Up</Name> <StartDate>2019-07-01</StartDate> <DueDate>2019-07-30</DueDate> </Task> <Task> <ID></ID> <Name>Concept Design</Name> <StartDate>2019-08-01</StartDate> <DueDate>2019-08-31</DueDate> </Task> </Tasks> </Job> </Jobs> XML; $xml = simplexml_load_string($str); // echo '<pre>', print_r($xml, 1), '</pre>'; foreach ($xml->Job as $job) { $state = (string)$job->State; if (!in_array($state, $required)) continue; echo "{$job->Name} — $state — "; foreach ($job->Tasks->Task as $task) { if ($task->Name == $state) { echo $task->DueDate . '<br>'; } } } Output Job 1 — Concept Design — 2019-08-31 EDIT - Alternative method $xml = simplexml_load_string($str); foreach ($xml->xpath("//Job") as $job) { $state = (string)$job->State; if (!in_array($state, $required)) continue; echo "{$job->Name} &mdash; $state &mdash; "; $task = $job->xpath("//Task[Name='$state']") ; echo $task[0]->DueDate . '<br>'; }
  5. Any chance of the full XML? That doesn't seem to match up with your processing.
  6. If, for other purposes, you require all records to be in the array then you can filter the records when you process them to gat those with a required status value EG $status_filter = function ($v) use ($required) { return in_array($v['job_status'], $required); }; foreach (array_filter($projects, $status_filter) as $proj) { // process $proj }
  7. Use an array to get the ones you want... $projects = array(); $required = ['Feasibility', 'Measure Up', 'Model Drawing', 'Concept Design', 'Developed Design', 'Resource Consent', 'Construction Documentation' ]; $xml=simplexml_load_string($response) or die("Error: Cannot create object"); foreach($xml->Jobs->Job as $item) { if (in_array((string)$item->State, $required)) { $projects[] = array( 'job_no' => (string)$item->ID, 'job_name' => (string)$item->Name, 'job_due' => (string)$item->DueDate, 'job_status' => (string)$item->State, 'job_staff' => (string)$item->Assigned->Staff->Name, ); } } usort($projects, function($a,$b) {return $b['job_due'] <=> $a['job_due']; } ); // reverse $a and $b for desc sort // $projects = array_reverse($projects); // no longer required This code is just plain wrong... while ($projects['job_status'] == ('Feasibility') && ('Measure Up') && ('Model Drawing') && ('Concept Design' ) && ('Developed Design' ) && ('Resource Consent' ) && ('Construction Documentation')) { and this is a waste of time and effort. Why just move a value from one variable to another and why put a single string variable inside quotes? $formatted = date('d/m/Y', strtotime($proj['job_due'])); $job_no ="{$proj['job_no']}"; $job_name ="{$proj['job_name']}"; $job_due ="$formatted"; $job_status ="{$proj['job_status']}"; $job_staff ="{$proj['job_staff']}";
  8. If your calc sheet looks like this then File/Save As... select CSV as the file type and save should give this Date,Title,Text 01/01/2019,Lukas:16:19,"Es war ein reicher Mann, der kleidete sich in Purpur und kostbares Leinen" 01/02/2019,Kolosser:3:13,Ertrage einer den andern und vergebt euch untereinander 01/03/2019,1.Petrus:5:10,"Der Gott aller Gnade, der euch berufen"
  9. If you are constrained to three columns, I'd go with Date | Book:chapter:verse | Text and I'd put the data into a conventional CSV format that can be opened directly by Excel - EG "01/01/19","Lukas:16:19","Es war ein reicher Mann, der kleidete sich in Purpur und kostbares Leinen" "01/02/19","Kolosser:3:13","Ertrage einer den andern und vergebt euch untereinander" "01/03/19","1.Petrus:5:10","Der Gott aller Gnade, der euch berufen"
  10. I see five distinct data items +----------+------------+-----------+---------+-----------------------------------------------------------------------------+ | Date | Book | Chapter | Verse | Text | +----------+------------+-----------+---------+-----------------------------------------------------------------------------+ | 01/01/19 | Lukas | 16 | 19 | Es war ein reicher Mann, der kleidete sich in Purpur und kostbares Leinen | | 01/02/19 | Kolosser | 3 | 13 | Ertrage einer den andern und vergebt euch untereinander` | | 01/03/19 | 1. Petrus | 5 | 10 | Der Gott aller Gnade, der euch berufen` | +----------+------------+-----------+---------+-----------------------------------------------------------------------------+
  11. If your connection fails then $link is not a valid connection value - so you cannot use mysqli_error($link) which requires a valid $link argument. I told you what to use instead some days ago. Read the replies if you can't read the manual.
  12. https://www.php.net/manual/en/mysqli.connect-error.php
  13. @Franz123 It would have been preferred, and a lot simpler, for you just to post a link to the HostPapa site article on Filezilla
  14. $rules does not exist prior to $rules = $resortPro->ssml_routes_for_search_results_pages(); so no point putting it before that line.
  15. The first thing to do is var_dump($rules); It should be an array. If it isn't then you need to invstigate why $resortPro->ssml_routes_for_search_results_pages() isn't returning an array.
  16. Even with unique constraints on username and on email, without restrictions on usernames you could potentially have this situation +------------+---------------+-----------------+------------------+ | Emp ID | Username | Email | Password | +------------+---------------+-----------------+------------------+ | 1 | [email protected] | [email protected] | s3cr3t | | 2 | [email protected]| [email protected] | s3cr3t | +------------+---------------+-----------------+------------------+ Your query would then find both employees Also, many companies use the convention that an employee's email address is <username> @ <domainname> The presence of @ in the username would render the address invalid.
  17. All you have so far is a string variable containing SQL code, so you are missing a few things. (You whould also be using a prepared query when using data from an external source such as GET or POST) You need to Connect to the mysql server (mysqli_connect) Prepare the query (mysqli_prepare) Bind the parameter (mysqli_stmt_bind_param) Execute the query. (mysqli_stmt_execute) [EDIT] Plus I think you may need some quotes in your ajax parameters data: { "itemid":itemID, "clear":1 },
  18. Post code we can read instead of redacted text and someone might look at it.
  19. Compare your $update->execute with mine.
  20. $attribute would be the key and $label would be the value $taxonomy_of_interest[$attribute] = $label;
  21. v5.6 equivalent would be $reset = isset($_POST['reset'][$id]) ? $_POST['reset'][$id] : 0;
  22. The script is using PDO, not mysqli "??" is a PHPv7 operator
  23. One way would be to use the $headings array. Provide a translation for all those you want to include and ignore those that are not in the array. You could also think about extending that array to provide the sequence for attribute output,
  24. Attribute which are arrays (like "image" are ignored, as are attributes with no values. Where no heading translation is provided the raw attribute name is output. <?php $headings = [ 'attribute_pa_pack-quantity' => 'Pack&nbsp;Qty', 'attribute_pa_variation' => 'Variation', 'sku' => 'SKU', 'variation_description' => 'Var&nbsp;Desc', 'variation_id' => 'Id', 'price_html' => 'Price' ]; $systems = []; foreach ($variations as $var) { $atts = array_values($var['attributes']); $key = $atts[0]; $kv = count($var); $ka = count($var['attributes']); if (!isset($systems[$key])) { $systems[$key] = []; } $systems[$key][] = array_merge(array_slice($var['attributes'], 1, $ka-1, 1), array_slice($var, 1, $kv-1, 1)); } echo '<pre>', print_r($systems, 1), '</pre>'; ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Example</title> <style type='text/css'> body { font-family: calibri, sans-serif; font-size: 10pt; } .system { width: 30%; float: left; margin-right: 30px; } .item { padding: 5px; margin-bottom: 15px; } .hdg { display: inline-block; width: 150px; font-weight: 600; } </style> </head> <body> <?php foreach ($systems as $sys => $sdata) { echo "<div class='system'><h3>$sys</h3>\n"; foreach ($sdata as $item) { echo "<div class='item'>\n"; foreach ($item as $h => $v) { if ($v && !is_array($v)) { $hd = $headings[$h] ?? $h; // use attribute key if no translation available echo "<div class='hdg'>{$hd}</div>$v<br>\n"; } } echo "</div>\n"; } echo "</div>\n"; } ?> </body> </html>
×
×
  • 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.