unistake Posted November 23, 2015 Share Posted November 23, 2015 (edited) Hi guys, I have this code here http://pastebin.com/WK36Jx0G It works as it should for the first loop but for each re-loop though I get the output 'Array' echoing from line 41's output. Example shown below.. From: MAN STR DUB 12:15 - 20:05 From: MANArray DUB SNN 17:30 - 23:15 Anyone understand why? Thanks Edited November 23, 2015 by unistake Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 23, 2015 Share Posted November 23, 2015 What is the overall goal? It looks like you are not going about this the right way. Quote Link to comment Share on other sites More sharing options...
unistake Posted November 23, 2015 Author Share Posted November 23, 2015 my goal is to combine each row from the mysql database where the date is the same. Then I am putting the departure, arrival, duty, begintimes and endtimes in to separate arrays. I want to show first deptarture airport of the day, every arrival airport != $base and the first begintime and last endtime. Kind of complicated! Hope it makes sense! Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 23, 2015 Share Posted November 23, 2015 (edited) Can you post an sql dump of your db please. I meant the the end goal, not how you are trying to get there. What should the correct result look like? Edited November 23, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
unistake Posted November 23, 2015 Author Share Posted November 23, 2015 (edited) This is an example of my table. CREATE TABLE IF NOT EXISTS `rosters` ( `RostersID` int(11) NOT NULL AUTO_INCREMENT, `Code` varchar(7) NOT NULL, `SectorDate` date NOT NULL, `Duty` varchar(12) NOT NULL, `Dep` varchar(10) NOT NULL, `BeginTime` varchar(10) NOT NULL, `EndTime` varchar(10) NOT NULL, `Arr` varchar(10) NOT NULL, `AddedOn` datetime NOT NULL, `Random` int(4) NOT NULL, PRIMARY KEY (`RostersID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13004 ; -- -- Dumping data for table `rosters` -- INSERT INTO `rosters` (`RostersID`, `Code`, `SectorDate`, `Duty`, `Dep`, `BeginTime`, `EndTime`, `Arr`, `AddedOn`, `Random`) VALUES (10854, 'TESTR', '2015-03-18', 'HSBY1130Z', 'TPS', '11:30', '22:30', '', '2015-03-06 09:06:29', 2135), (10853, 'TESTR', '2015-03-17', '8642', 'BVA', '17:25', '20:00', 'TPS\r', '2015-03-06 09:06:28', 2135), (10852, 'TESTR', '2015-03-17', '8641', 'TPS', '14:20', '17:00', 'BVA\r', '2015-03-06 09:06:28', 2135), (10850, 'TESTR', '2015-03-16', '9062', 'TPS', '18:30', '20:15', 'BGY\r', '2015-03-06 09:06:27', 2135), (10849, 'TESTR', '2015-03-15', '6078', 'CIA', '20:35', '21:45', 'TPS\r', '2015-03-06 09:06:27', 2135), (10848, 'TESTR', '2015-03-15', '6079', 'TPS', '19:00', '20:10', 'CIA\r', '2015-03-06 09:06:27', 2135), (10847, 'TESTR', '2015-03-15', '9858', 'HHN', '16:15', '18:35', 'TPS\r', '2015-03-06 09:06:27', 2135); Edited November 23, 2015 by unistake Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 23, 2015 Share Posted November 23, 2015 Give me an example of what the correct output looks like from that table. Quote Link to comment Share on other sites More sharing options...
unistake Posted November 23, 2015 Author Share Posted November 23, 2015 (edited) for information:$base = TPS; the below is what I am trying to acheive. They outputs below are organised by date from the table above. From: HHN CIA TPS 16:15-21:45 From: TPS BGY 18:30-20:15 From: TPS BVA 14:20-20:00 From: TPS '' 11:30-22:30 Edited November 23, 2015 by unistake Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 23, 2015 Share Posted November 23, 2015 (edited) Its not clear how your data output correlates. Please provide a detailed description of the previous post. So far I have this output: Edited November 23, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
unistake Posted November 23, 2015 Author Share Posted November 23, 2015 (edited) Sorry to be 100% correct, this is how I want my output to be for this particular rows in the mysql db. $base = "TPS"; $crewcode = "TESTR"; (15-03-2015) HHN <---- Dep != $baseCIA <-----Arr != first Dep13:25 - 21:45 <----first BeginTime from 15-03-2015 - last EndTime from 15-03-2015 (16-03-2015) '' <---- Dep != $base (this case, Dep == $base) shows blank. TPS = $base;BGY <-----Arr != first Dep18:30 - 22:25 <----first BeginTime from 16-03-2015 - last EndTime from 16-03-2015 (17-03-2015) '' <---- Dep != $base (this case, Dep == $base) shows blank. TPS = $base;BVA <-----Arr != first Dep14:20 - 20:00 <----first BeginTime from 17-03-2015 - last EndTime from 17-03-2015 Edited November 23, 2015 by unistake Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 23, 2015 Share Posted November 23, 2015 Times you are giving dont even exist in the database. There is no 13:25 or 22:25 anywhere in the data. Quote Link to comment Share on other sites More sharing options...
unistake Posted November 23, 2015 Author Share Posted November 23, 2015 Sorry the above output should be like this, I don't know where I got those previous times from! (15-03-2015) HHN <---- Dep != $baseCIA <-----Arr != first Dep16:15 - 21:45 <----first BeginTime from 15-03-2015 - last EndTime from 15-03-2015 (16-03-2015) '' <---- Dep != $base (this case, Dep == $base) shows blank. TPS = $base;BGY <-----Arr != first Dep18:30 - 20:15 <----first BeginTime from 16-03-2015 - last EndTime from 16-03-2015 (17-03-2015) '' <---- Dep != $base (this case, Dep == $base) shows blank. TPS = $base;BVA <-----Arr != first Dep14:20 - 20:00 <----first BeginTime from 17-03-2015 - last EndTime from 17-03-2015 Quote Link to comment Share on other sites More sharing options...
benanamen Posted November 23, 2015 Share Posted November 23, 2015 (edited) Lets forget the code a minute. Your standing next to the arrival/departure board at XYZ Airport. Now tell your buddy standing next to you what you want to know about it in a simple complete explanation. I am still not grasping what your wanting to know about the information. Something like: We are at airport XYZ on 3-6-2015. There is an arrival coming from HHN at 16:15 and then it is leaving to TPS at 18:35. I WANT TO KNOW................?????? Edited November 23, 2015 by benanamen Quote Link to comment Share on other sites More sharing options...
Barand Posted November 23, 2015 Share Posted November 23, 2015 This should get you started SELECT dep1.SectorDate , dep1.Dep , arrs , firstBegin , lastEnd FROM ( SELECT t.SectorDate , IF(Dep='TPS', NULL, Dep) as Dep , firstBegin , lastEnd FROM rosters r JOIN ( SELECT SectorDate , MIN(BeginTime) as firstBegin , MAX(EndTime) as lastEnd FROM rosters GROUP BY SectorDate ) t ON r.SectorDate=t.SectorDate AND r.BeginTime=t.firstBegin ) dep1 LEFT JOIN ( SELECT SectorDate , GROUP_CONCAT(Arr ORDER BY BeginTime separator ', ') as arrs FROM rosters WHERE 'TPS' <> Arr GROUP BY SectorDate ) a USING (SectorDate) GROUP BY SectorDate; +------------+------+------+------------+---------+ | SectorDate | Dep | arrs | firstBegin | lastEnd | +------------+------+------+------------+---------+ | 2015-03-15 | HHN | CIA | 16:15 | 21:45 | | 2015-03-16 | | BGY | 18:30 | 20:15 | | 2015-03-17 | | BVA | 14:20 | 20:00 | | 2015-03-18 | | | 11:30 | 22:30 | +------------+------+------+------------+---------+ 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.