Jump to content

Recommended Posts

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 by unistake
Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1526964
Share on other sites

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 by unistake
Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1526967
Share on other sites

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 by unistake
Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1526969
Share on other sites

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 != $base
CIA                                         <-----Arr != first Dep
13: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 Dep
18: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 Dep
14:20 - 20:00                        <----first BeginTime from 17-03-2015 - last EndTime from 17-03-2015

Edited by unistake
Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1526971
Share on other sites

Sorry the above output should be like this, I don't know where I got those previous times from!

 

 

                                                (15-03-2015)

HHN                                        <---- Dep != $base
CIA                                         <-----Arr != first Dep
16: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 Dep
18: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 Dep
14:20 - 20:00                        <----first BeginTime from 17-03-2015 - last EndTime from 17-03-2015

Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1526984
Share on other sites

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 by benanamen
Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1527006
Share on other sites

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   |
+------------+------+------+------------+---------+
  • Like 2
Link to comment
https://forums.phpfreaks.com/topic/299559-echoing-array/#findComment-1527013
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.