spikereloaded Posted May 28, 2013 Share Posted May 28, 2013 Hi guys I'm trying to add into our travel system different travel times based on where your travelling from and where your travelling to. Now in theory I have the general concept down, however the way i'm currently doing it seems veryyyy long winded and not very server friendly. I've got this so far: if($ir['location'] == 1 && $_GET['to'] == 2) { $time = "5"; } else if ($ir['location'] == 1 && $_GET['to'] == 3) { $time = "15"; } if($ir['location'] == 1 && $_GET['to'] == 4) { $time = "10"; } and this goes on until to == 8. Now this is only for calculating the travelling time from location 1 and i want to calculate travelling times for the other seven locations as well, and im thinking repeating what I've got above, 7 more times, is not the best way to do it. Anybody got another method that i'm missing here? thanks in advance Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 28, 2013 Share Posted May 28, 2013 you can maybe look up stuff with geo locations and they have some classes on phpclasses.org and basically add your own longitude and latitude to you locations when you edit/create them to simulate "real life" its not an easy task but I'm sure can be done Quote Link to comment Share on other sites More sharing options...
spikereloaded Posted May 28, 2013 Author Share Posted May 28, 2013 i was thinking about this after i posted while i was driving to the gym....i could just add the infor to the databse, then do a query to select from the table where user location = 1 and travelling to location = 2 and so on. Simple! Now just got to spend time going through every combination of travelling and put it in the database as a new table! Thanks for the input Kyle, good idea but probably not ideal for what I'm looking for atm. Quote Link to comment Share on other sites More sharing options...
Djkanna Posted May 28, 2013 Share Posted May 28, 2013 Could do something like. <?php $locationTimes = array ( 1 => array ( 2 => 10, 3 => 15, 4 => 5, 5 => 3, 6 => 2, 7 => 20, ), 2 => array ( 1 => 10, 3 => 15, 4 => 5, 5 => 3, 6 => 2, 7 => 20, ), 3 => array ( 1 => 10, 2 => 15, 4 => 5, 5 => 3, 6 => 2, 7 => 20, ), 4 => array ( 1 => 10, 2 => 15, 3 => 5, 5 => 3, 6 => 2, 7 => 20, ), 5 => array ( 1 => 10, 2 => 15, 3 => 5, 4 => 3, 6 => 2, 7 => 20, ), 6 => array ( 1 => 10, 2 => 15, 3 => 5, 4 => 3, 5 => 2, 7 => 20, ), 7 => array ( 1 => 10, 2 => 15, 3 => 5, 4 => 3, 5 => 2, 6 => 20, ), ); if ( array_key_exists ( $ir['location'], $locationTimes ) && array_key_exists ( $_GET['to'], $locationTimes[$ir['location']] ) ) { $time = $locationTimes[$ir['location']][$_GET['to']]; } else { $time = 20; //default. } Array of all locations ( ID ), then for each location have an array of other locations ( ID ) and the respective time. Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 28, 2013 Share Posted May 28, 2013 (edited) that's a pretty easy straight forward way :p. or create a hypothetical grid map and each location is on its own cell like A(3, 2) B(1,-3) now you take the distance between each x cord^ + each y cord^ and get the square root of that value. then you need to determine travel speed and thee you go. btw the answer is 3-1=2^= 4 + 2- -3=5^ =25. 4+25=29. square root of 29= 5.4 rounded up Edited May 30, 2013 by KyleMassacre typo Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 29, 2013 Share Posted May 29, 2013 Something like this? [ATTACH=CONFIG]982[/ATTACH] 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.