-
Posts
24,612 -
Joined
-
Last visited
-
Days Won
834
Everything posted by Barand
-
So you're writing an application for those in your company who don't know where they are when they are browsing reports?
-
My results could be right then - there is the possibility that my ISP is in Salford. As for the region, it could be Google has a Londoner's view of England where anywhere beyond the end of their Northern underground line is "the North" (beware, here be dragons!)
-
It will get location info, but not necessarily the correct info. For me, it returned Country : GB Region: West Riding of Yorkshire City : Salford. The country is correct. However I do not live in Salford or the West Riding of Yorkshire. Also, Salford is in Lancashire, not in the West Riding of Yorkshire. I'd class it as a "Failed". (Moved to new topic)
-
Anything received from an external source can be "fiddled with".
-
You would only be sending a product id number, not your bank details.
-
I'm surprised you don't appear store the data anywhere, except maybe in SESSION, so you have to reenter all the data each time you want to view the analyses. And why 4 pages and not just
-
Does position: fixed; work?
-
You could do it the same way you did it 4 hours ago
-
To get a five record rolling average you need to calculate it from the current record and the four records immediately prior to the current one.
-
In your results, the only one that is a correct rolling average of the last 5 records is the last one. In my results, they all are. But if that is what you want, carry on (and note that, as a rule, you should not store derived data in a database)
-
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 +-------+----------+---------+----------+-------------------+-----------------+
-
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 | +-------+---------+----------+
-
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> </td>"; } } $tdata .= "<td> </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>
-
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} — $state — "; $task = $job->xpath("//Task[Name='$state']") ; echo $task[0]->DueDate . '<br>'; }
-
Any chance of the full XML? That doesn't seem to match up with your processing.
-
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 }
-
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']}";
-
importing data from calc via Google-API to google-Calendar!?
Barand replied to dil_bert's topic in Miscellaneous
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" -
importing data from calc via Google-API to google-Calendar!?
Barand replied to dil_bert's topic in Miscellaneous
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" -
importing data from calc via Google-API to google-Calendar!?
Barand replied to dil_bert's topic in Miscellaneous
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` | +----------+------------+-----------+---------+-----------------------------------------------------------------------------+ -
Error establishing a database connection - wordpress-issues
Barand replied to dil_bert's topic in Applications
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. -
Error establishing a database connection - wordpress-issues
Barand replied to dil_bert's topic in Applications
https://www.php.net/manual/en/mysqli.connect-error.php -
$rules does not exist prior to $rules = $resortPro->ssml_routes_for_search_results_pages(); so no point putting it before that line.