jk1 Posted February 11, 2019 Share Posted February 11, 2019 I have designed a simple page to get meeting room details to display on our dashboards. I would like to filter for today's date (start date) and then sort by room name (name) if possible: (if you believe this could be written better (the server is on php 5.4) then also please let me know: $ch = curl_init($url); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch); $response = strip_tags($response); $response = trim(preg_replace('/\s+/', ' ', $response)); $bookingArray = json_decode($response, true); $timezone = date_default_timezone_get(); { foreach($bookingArray["result"]["bookings"] as $booking) { echo $booking["name"] . " - " . $booking["eventStatus"]["type"] . " - ". substr($booking["startDate"], -20) . " - " . substr($booking["endDate"], -20) . " - " . $booking["eventName"] . " - ". $booking["primaryContact"]["givenName"] . " " . $booking["primaryContact"]["surName"] . "<br>"; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/308306-filter-for-todays-date-and-sort-by-name/ Share on other sites More sharing options...
requinix Posted February 11, 2019 Share Posted February 11, 2019 Are you submitting some request to an API? Does that have any sort of searching, filtering, or sorting capability? $response = strip_tags($response); $response = trim(preg_replace('/\s+/', ' ', $response)); Why are those lines there? Are you sure you need them? (You shouldn't.) Does the script still work if you remove them? (It should.) Quote Link to comment https://forums.phpfreaks.com/topic/308306-filter-for-todays-date-and-sort-by-name/#findComment-1564380 Share on other sites More sharing options...
jk1 Posted February 11, 2019 Author Share Posted February 11, 2019 2 hours ago, requinix said: Are you submitting some request to an API? Does that have any sort of searching, filtering, or sorting capability? $response = strip_tags($response); $response = trim(preg_replace('/\s+/', ' ', $response)); Why are those lines there? Are you sure you need them? (You shouldn't.) Does the script still work if you remove them? (It should.) I am submitting a request to an api - it then returns the 7 fields on a line in a big list. ill check to see if the api can filter/sort and also remove the response as well - I'm a beginner to php and only got this far due to my sql knowledge - in php is there an order by command? Quote Link to comment https://forums.phpfreaks.com/topic/308306-filter-for-todays-date-and-sort-by-name/#findComment-1564381 Share on other sites More sharing options...
requinix Posted February 11, 2019 Share Posted February 11, 2019 6 hours ago, jk1 said: in php is there an order by command? Basically, yes, and if the API can't do what you need (I doubt it can) then your PHP can do it instead. Quote Link to comment https://forums.phpfreaks.com/topic/308306-filter-for-todays-date-and-sort-by-name/#findComment-1564387 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.