Jump to content

Barand

Moderators
  • Posts

    24,345
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. @requinix - It was tricky getting the timing just right
  2. try $sql = "SELECT co.id , co.name , car.id , car.model FROM companytest co INNER JOIN cartest car ON co.id = car.make ORDER BY co.id, car.id"; $res = $db->query($sql); $cars = []; $prev = ''; while (list($coid, $coname, $cid, $model) = $res->fetch_row()) { if (!isset($cars[$coid])) { $cars[$coid] = ['id' => $coid, 'name' => $coname, 'cars' =>[] ]; } $cars[$coid]['cars'][] = ['id' => $cid, 'model' => $model]; } the data mysql> select * from companytest; +------+----------------+ | id | name | +------+----------------+ | 1 | Ford | | 3 | General Motors | | 5 | Chrysler | +------+----------------+ 3 rows in set (0.00 sec) mysql> select * from cartest; +------+------+------------+ | id | make | model | +------+------+------------+ | 1 | 1 | Mustang | | 2 | 1 | Fusion | | 3 | 3 | Corvette | | 4 | 3 | Escalade | | 5 | 5 | Charger | | 6 | 5 | Challenger | +------+------+------------+ 6 rows in set (0.00 sec)
  3. Do you have error reporting turned on? Have you checked the values of mysqli_error? I cannot do it for you.
  4. Similarly, the code you just posted, the input to simplexml_load_string() is $result->GetDailyListingSummaryResult->any That should be the XML.
  5. First step to debugging is to have error_reporting switched on and also check for mysqli_error values after attempting queries. Where is $resultat defined? If it isn't it should be throwing an "undefined variable" error.
  6. Your data shows team as character field, yet you create a table with team name as INT and goals as varchar(). As this table contains only one field for goals, and you say you want both a count and a total, which goes in the new table (count or total). And why are you doing this at all? You can get these by query any time, you should not store data derived from the data in databases.
  7. That is NOT xml, it is a var dump output of some xml data that has been processed by simplexml.
  8. Can you describe what is is you are trying to do so I can make some sense of your code.
  9. You might want to test that solution before you go any further
  10. Consider this scenario. You have the following statuses 1 - not started 2 - work in progress 3 - completed. So now, anything not completed has "status < 3" and all works well with your query. You boss now tells you they are introducing new status codes 4 - temporarily on hold. 5 - cancelled status < 3 no longer gives you all those that are not completed.
  11. Make sure your bind_param() has the params in the same order as the placeholders in the query
  12. json_decode to put it in an array. loop through the array trim tabs and spaces from field values write to csv file $arr = json_decode(file_get_contents('result.txt'),1); // create array feom json data $arr = array_filter($arr); // remove empty records $fp = fopen('result.csv','w'); // open output file foreach ($arr as $record) { $rec = array_map('trim', $record); fputcsv($fp,$rec); } fclose($fp); Your currency values should not be stored in a DB with currency symbols and comma formatting so you have some extra work to do there.
  13. We will try to type slowly and loudly for you
  14. Use a left join. If the is no matching se record then values from the se table will be null. Use explicit A JOIN B ON condition syntax and not the FROM A,B WHERE. You can use IFNULL() to check the status SELECT ua.id , ua.security_key , ua.creation , ua.last_login , ua.f_name , ua.l_name , ua.email , ua.title , ua.org_name , ua.org_size , ua.manage_num , ua.manage_direct_num , ua.phone , IFNULL(se.status, 'No match') as status FROM user_accts AS ua LEFT JOIN sessions AS se ON se.author_id = ua.id AND se.status < ? WHERE ( $search_filter >= ? AND $search_filter <= ? ) ORDER BY $search_filter DESC
  15. Don't double post. Closing this topic.
  16. To use SUM() then you do need to convert mysql> SELECT SEC_TO_TIME(SUM(TIMESTAMPDIFF(SECOND,t_in,t_out))) as total --> FROM temptimes; +----------+ | total | +----------+ | 21:30:00 | +----------+
  17. Or, you could just use the TIMEDIFF() function instead of those conversions mysql> CREATE TEMPORARY TABLE temptimes (t_in DATETIME, t_out DATETIME); mysql> INSERT INTO temptimes VALUES -> ('2016-07-27 08:30:00', '2016-07-27 17:45:00'), -> ('2016-07-27 19:30:00', '2016-07-28 07:45:00'); mysql> SELECT t_in, t_out, TIMEDIFF(t_out, t_in) as hrs FROM temptimes; +---------------------+---------------------+----------+ | t_in | t_out | hrs | +---------------------+---------------------+----------+ | 2016-07-27 08:30:00 | 2016-07-27 17:45:00 | 09:15:00 | | 2016-07-27 19:30:00 | 2016-07-28 07:45:00 | 12:15:00 | +---------------------+---------------------+----------+
  18. +--------------+ +----------------+ +--------------------+ | team | | member | | timeworked | +--------------+ +----------------+ +--------------------+ | team_id (PK) |---+ | member_id (PK) |---+ | timeworked_id (PK) | | teamname | +--<| team_id | +--<| member_id | +--------------+ +----------------+ | timein | | timeout | +--------------------+
  19. in the file you posted earlier (Fill_Id.txt) you have this line $xml = simplexml_load_string($ParseData); So it looks as though $parseData is the XML. Do you have anything similar for this new bit of data?
  20. If I remove the references to that method, this seems to work $data = array ( 0 => (array( 'DOCID' => '96651', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-102 ', )), 1 => (array( 'DOCID' => '96646', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCTITLE' => 'Order No. 3430 - Order Approving Modification One', 'DOCKETID' => 'CP2015-106 ', )), 2 => (array( 'DOCID' => '96645', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-114 ', )), 3 => (array( 'DOCID' => '96648', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-75 ', )), 4 => (array( 'DOCID' => '96649', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-76 ', )), 5 => (array( 'DOCID' => '96650', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-86 ', )), 6 => (array( 'DOCID' => '96652', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2015-93 ', )), 7 => (array( 'DOCID' => '96640', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-237 ', )), 8 => (array( 'DOCID' => '96641', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-238 ', )), 9 => (array( 'DOCID' => '96643', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-241 ', )), 10 => (array( 'DOCID' => '96653', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-242 ', )), 11 => (array( 'DOCID' => '96647', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-246 ', )), 12 => (array( 'DOCID' => '96644', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'CP2016-3 ', )), 13 => (array( 'DOCID' => '96641', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'MC2016-164 ', )), 14 => (array( 'DOCID' => '96643', 'DATERECD' => '2016-07-15T00:00:00-04:00', 'DOCKETID' => 'MC2016-167 ', )), ); usort($data, function($a,$b) { list($a1,$a2,$a3) = splitParts($a['DOCKETID']); list($b1,$b2,$b3) = splitParts($b['DOCKETID']); $x = strcmp($a1,$b1); if ($x == 0) { $y = $b2 - $a2; if ($y == 0) { return $b3 - $a3; } return $y; } return $x; }); function splitParts($s) { $k = strlen($s); $a = ['','','']; $i = 0; $p = 0; while ($i < $k) { $c = $s[$i++]; if (ctype_digit($c) && $p==0) $p = 1; if ($c=='-') { $c = $s[$i++]; ++$p; } $a[$p] .= $c; } return $a; } print_r ($data); giving Array ( [0] => Array ( [DOCID] => 96647 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-246 ) [1] => Array ( [DOCID] => 96653 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-242 ) [2] => Array ( [DOCID] => 96643 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-241 ) [3] => Array ( [DOCID] => 96641 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-238 ) [4] => Array ( [DOCID] => 96640 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-237 ) [5] => Array ( [DOCID] => 96644 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2016-3 ) [6] => Array ( [DOCID] => 96645 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-114 ) [7] => Array ( [DOCID] => 96646 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCTITLE] => Order No. 3430 - Order Approving Modification One [DOCKETID] => CP2015-106 ) [8] => Array ( [DOCID] => 96651 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-102 ) [9] => Array ( [DOCID] => 96652 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-93 ) [10] => Array ( [DOCID] => 96650 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-86 ) [11] => Array ( [DOCID] => 96649 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-76 ) [12] => Array ( [DOCID] => 96648 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => CP2015-75 ) [13] => Array ( [DOCID] => 96643 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => MC2016-167 ) [14] => Array ( [DOCID] => 96641 [DATERECD] => 2016-07-15T00:00:00-04:00 [DOCKETID] => MC2016-164 ) )
  21. Yes, I saw the manual - no __set_state() in the list of methods If you re-arrange your array, so that the id to sort on is the key, then you could do the same user sort on that key.
  22. Given that the structure of the new array is nothing like the structure of the original, it is hardly surprising that it doesn't work. The array also contains references to undocumented SimpleXMLElement::__set_state() method.
×
×
  • 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.