Which mechanic can I use to order an array?

I am stuck in a very strange problem. I mean, I don’t know how to threaten this.

Basically, I have a web page where I list all the stops for a specific bus route (example, route_id = 141). Once upon a time, a route can start from point A and go to point B so theoretically from one end to the other end point. BUT, someday, the same route can begin its journey somewhere between A and B and go to point A or B.

You can see a live working example at this address: http://stm.tranzit.ca/bus/stops/85/Hochelaga/

My super draw:

Regular trip
Start(A) ----------------------------------- End(B)

Sometime
                 Start --------------------- End(B)
Start(A) ---------------------- End

etc. It will always be between points A and B. 90% of the time from A to B, and the remaining 10% can be somewhere between them to another point between them (sometimes from the middle to A or B).

Ok. , stop_sequence. , 1, 2 .. ( , ..).

, , (A-B, B-A, A-middle, middle-B ..).

, , A-B, B-A, A-Middle B-Middle, 4 . , .

, A B . stop_sequence 35.

1   #53014  Station Frontenac (Frontenac / Ontario)

... 2, 3. etc..

34  #53293  Honoré-Beaugrand / Roux  
35  #54257  Station Honoré-Beaugrand / Sherbrooke    
36  #53290  Saint-Donat / Sherbrooke     
37  #53265  Saint-Donat / De Forbin-Janson   
38  #54676  Saint-Donat / De Grosbois    
39  #54674  Saint-Donat / Roi-René   
40  #54672  Saint-Donat / les Reaux  
41  #54668  Saint-Donat / Chénier    
42  #54661  Joseph-Renaud / Yves-Prévost     
43  #54646  Joseph-Renaud / Châtillon    
44  #54629  Joseph-Renaud / Wilfrid-Pelletier    
45  #54605  Joseph-Renaud / Châteauneuf  
46  #54609  Châteauneuf / Vaujours   
47  #54610  Châteauneuf / Rabelais   
48  #54612  Châteauneuf / de la Loire    
49  #54621  Châteauneuf / Roi-René   
50  #54623  Châteauneuf / des Ormeaux    
51  #54639  Châteauneuf / Rondeau    
52  #54724  Rondeau / Georges    
53  #54735  Rondeau / De La Vérendrye    
54  #54738  Rhéaume / Chaumont   
55  #54740  Chaumont / Guy   
56  #54741  Chaumont / Azilda    
57  #54742  Yves-Prévost / Azilda    
58  #54659  des Ormeaux / Chaumont

B.

1   #54257  Station Honoré-Beaugrand / Sherbrooke    
2   #53290  Saint-Donat / Sherbrooke     
3   #53265  Saint-Donat / De Forbin-Janson   
4   #54676  Saint-Donat / De Grosbois    
5   #54674  Saint-Donat / Roi-René   
6   #54672  Saint-Donat / les Reaux  
7   #54668  Saint-Donat / Chénier    
8   #54661  Joseph-Renaud / Yves-Prévost     
9   #54646  Joseph-Renaud / Châtillon    
10  #54629  Joseph-Renaud / Wilfrid-Pelletier    
11  #54605  Joseph-Renaud / Châteauneuf  
12  #54609  Châteauneuf / Vaujours   
13  #54610  Châteauneuf / Rabelais   
14  #54612  Châteauneuf / de la Loire    
15  #54621  Châteauneuf / Roi-René   
16  #54623  Châteauneuf / des Ormeaux    
17  #54639  Châteauneuf / Rondeau    
18  #54724  Rondeau / Georges    
19  #54735  Rondeau / De La Vérendrye    
20  #54738  Rhéaume / Chaumont   
21  #54740  Chaumont / Guy   
22  #54741  Chaumont / Azilda    
23  #54742  Yves-Prévost / Azilda    
24  #54659  des Ormeaux / Chaumont

, , stop_sequence 1 35. , 36 . , 35 58 24. , .

, , PHP? let say , stop_sequence 1 stop_sequence 35, , .

, -, stop_sequence , , , stop_sequence 1, 24 . , stop_sequence MySQL, stop_sequence, resulst stop_sequence 1 , 1 .., , .

PHP, , X , .

, SQL-, :

SELECT      t.trip_id, t.trip_headsign, st.stop_sequence, s.stop_id, s.stop_code, s.stop_name
FROM        trips AS t
LEFT JOIN   stop_times AS st ON st.trip_id = t.trip_id
LEFT JOIN   stops AS s ON s.stop_id = st.stop_id
WHERE       t.route_id = 141
    AND     t.trip_id IN (
        SELECT trip_id
        FROM (
            SELECT trip_id
            FROM (
                SELECT      COUNT(*) AS count, trips.trip_id, trips.trip_headsign
                FROM        trips
                LEFT JOIN   stop_times ON trips.trip_id = stop_times.trip_id
                WHERE       route_id = 141
                    AND     trips.trip_id LIKE (SELECT CONCAT(service_id, "%") FROM calendar_dates WHERE date = "20120628")
                GROUP BY    trips.trip_id
            ) a
            GROUP BY count, trip_headsign
        ) a
    )
GROUP BY    t.trip_id, st.stop_id
ORDER BY    t.trip_id ASC, st.stop_sequence ASC

trip_id , A-B, B-A, A-middle ..

stop_sequence -

stop_id stop_code - ( )

trip_headsign 141-W 141-N ( , ).!

, ( ). , .

1 () 8. , 1 1, 2 .. 8.

1 () 8. , 1, 7 8.

.

:

: - 1 () - 2 - 3 .... - 6 - 1 () - 7 ( , ) - 8 ( , )

+5
1

:

  • , , A, - B
  • :
    • A, / .
    • B, / .

, .

+1
source

All Articles