Jump to content


  • Posts

  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

jarvis's Achievements

Advanced Member

Advanced Member (4/5)




Community Answers

  1. Ah of course! Thank you, that's sorted it Very much appreciated
  2. Hi @Barand Many thanks (as usual!) for the reply. I added a field to the initial array called 'sort_date' => $date The $date format is dmY I've amended the usort function: usort($attendees, function($a, $b) { $x = $a['sort_date']<=>$b['sort_date']; if ($x == 0) return $a['course']<=>$b['course']; return $x; }); But sadly, the courses don't seem to be in the order of the sort date (which would be ascending). Instead, they just seem to be ignoring the sorting. Have I done something wrong?
  3. Good morning, I'm hoping someone can please kindly help. I have an array of data: $attendees[] = array( 'course'=> $course_title, 'date' => $course_start_date, 'name' => $order->get_billing_first_name().' '.$order->get_billing_last_name(), 'email' => $order->get_billing_email(), 'phone' => $order->get_billing_phone(), 'qty' => $result['quantity'], 'order' => $order_id_number ); I then group the data: // group data by course $result = array(); foreach ($attendees as $attendee): $result[$attendee['course']][] = $attendee; endforeach; Using a foreach loop (foreach ($result as $itemName => $rows):) I output the data. This works fine. However, the order isn't right. I'd like to sort the output by alphapetical. So I added the following before the foreach: sort($result); However, it doesn't make a jot of difference. Have I missed something really obvious as to why its not working? Thanks
  4. Hi @Barand Is that due to the `mfs_training_course_email_notifications` as opposed to SELECT * FROM mfs_training_course_email_notifications (no backticks) It's the only difference I can see? You're right! $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM `$table_name` WHERE `start_date` = %s AND `email_sent` = %d", $test, $email_sent), Worked! Thanks
  5. Hi All, Apologies if this is in the wrong place. I'm using Wordpress to run a SQL query as per the below: $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE 'start_date' = %s AND 'email_sent' = %d", $test, $email_sent), ARRAY_A); This outputs the following: SELECT * FROM mfs_training_course_email_notifications WHERE 'start_date' = '2023-06-17' AND 'email_sent' = 0 Which returns 0 results. However, if I know there is a result. If I go to PHPMyAdmin and run the following: SELECT * FROM `mfs_training_course_email_notifications` WHERE `start_date` = '2023-06-17' AND `email_sent` = 0 It works and returns a result. If I alter the code: $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE 'email_sent' = %d", $email_sent), ARRAY_A); Therefore: SELECT * FROM mfs_training_course_email_notifications WHERE 'email_sent' = 0 It returns results, so seems the issue is the start_date part. However, I'm perplexed as to why? The start_date column is a date field - in case that makes any odds!? Am trying to prevent doing the last search, then adding an IF statement to check the date. Would rather try to include both in the initial query to make things quicker/streamlined. Hope that makes sense!?
  6. Literally: $json[] = array( 'name' => $itemName, 'desc' => 'Booking #'.$row["booking_id"], 'values' => $data ); $itemName = ''; That works! Thanks, pretty obvious really
  7. Thanks @kicken Sadly, the data has to be that format as it's passed to into creating a gantt chart using a 3rd party tool (a demo can be seen here).
  8. Hi All, I've got the following code, which creates my JSON feed. It works perfectly: // group data by suite $result = array(); foreach ($bookings as $booking) : $result[$booking['suite']][] = $booking; endforeach; // create our array for the gantt json feed $json = array(); $count = 0; foreach ($result as $itemName => $rows) : $count++; $customClass = ($count % 2 == 1) ? "ganttRed" : "ganttBlue"; foreach ($rows as $row) : $quantity = array_shift($row['quantity']); $data = [[ 'from' => $row["start_date"], 'to' => $row["end_date"], 'label' => $row['person']." (".$quantity.")", 'desc' => $row['name']."<br/>".$row['telephone']."<br/>".$row['email'], 'customClass' => $customClass ]]; $json[] = array( 'name' => $itemName, 'desc' => 'Booking #'.$row["booking_id"], 'values' => $data ); endforeach; endforeach; The only downside, is that the name column outputs each time: [ { "name":"Suite 1", "desc":"Booking #835", "values":[ { "from":"09\/08\/2022", "to":"09\/14\/2022", "label":"Single Room", "desc":"john@smith.com", "customClass":"ganttRed" } ] }, { "name":"Suite 1", "desc":"Booking #833", "values":[ { "from":"09\/06\/2022", "to":"09\/09\/2022", "label":"Ensuite", "desc":"fred@west.com", "customClass":"ganttRed" } ] } ] What I'd like is the following: [ { "name":"Suite 1", "desc":"Booking #835", "values":[ { "from":"09\/08\/2022", "to":"09\/14\/2022", "label":"Single Room", "desc":"john@smith.com", "customClass":"ganttRed" } ] }, { "name":"", "desc":"Booking #833", "values":[ { "from":"09\/06\/2022", "to":"09\/09\/2022", "label":"Ensuite", "desc":"fred@west.com", "customClass":"ganttRed" } ] } ] I wonder how I may go about achieving this please?
  9. Many thanks for the help. I'm trying to resolve the issue using SQL to help prevent filtering many results. Due to the way the data is stored, it's a little fiddly but will try to fathom it out. The help on here is always very much appreciated Thanks again
  10. I'm using some jQuery to refresh the script every minute or so So in theory, it should mean if someone left the page open, once it refreshes, it will remove any out of date files
  11. Thanks @Barand I realised my naming convention wasn't the best. Therefore, I updated the original post code as $todays_date was a misleading name. This actually refers to the date associated to the file and not the actual date of today - if that makes sense? Apologies, I caused the confusion! I've also amended the code as per your comments. Sadly, I still have the issue
  12. Good afternoon, I've got myself in a muddle over what I thought should be some simple code. Files are uploaded in a CMS and have a date field next to them (returning in format of d/m/Y). So when a new file is added, the user selects the day the file(s) should display For example: File A - 23/08/2022 File B - 24/08/2022 File C - 25/08/2022 Files for the previous day need to display on the current day until a set time (in this instance 13:59:59) I've setup some code as follows: $yesterday = new DateTime("yesterday 13:59:59", new DateTimeZone('Europe/London')); echo "Yesterday " . $yesterday->format('d/m/Y H:i:s') . "<br/>"; date_default_timezone_set('Europe/London'); echo "Today " . date("d/m/Y h:i:s") . "<br/>"; $tomorrow = new DateTime("tomorrow 00:00:01", new DateTimeZone('Europe/London')); echo "Tomorrow " . $tomorrow->format('d/m/Y H:i:s') . "<br/>"; So currently, this outputs: Yesterday 23/08/2022 13:59:59 Today 24/08/2022 02:37:08 Tomorrow 25/08/2022 00:00:01 The above I use to check the date/times whilst I play around with the code logic. I then loop through the uploaded files and dates from the CMS. In the loop, I grab the date (stored as d/m/Y) next to each file so therefore adjust it: $file_date = DateTime::createFromFormat('d/m/Y', $date); Then within the loop, I also add a check to display the file if its the right day/time range: #if today is greater than yesterday but less than tomorrow if($file_date->format('d/m/Y H:i:s') > $yesterday->format('d/m/Y H:i:s') && $file_date->format('d/m/Y H:i:s') < $tomorrow->format('d/m/Y H:i:s') ): //display the file URL endif; It then shows File A and File B but surely should only show File A as it's after Yesterday 23/08/2022 13:59:59 I think I've missed something really obvious but can't see for looking!
  13. OMG @mac_gyver Thank you so much (and others who read and commented). I can indeed confirm that works! Honestly, I thought I was going mad but that's absolutely brilliant! Thank you again so much, it truly is very much appreciated!
  14. @mac_gyver Yes, it seems to be a right pain and cannot for the life of me find a solution - which is most annoying!! Thanks again
  15. The site is a Wordpress site and uses a plugin. Basically, it adds a dropdown of fontawesome icons against the taxonomy field. You select the icon, click save and the data is stored in the termemta table. The meta_key is icon and the meta_value looks like: { "style" : "regular", "id" : "circle-dot", "label" : "Circle dot", "unicode" : "f192" } It would make sense to escape the data when storing. If I access the value direct from the database, it shows as: f192 It therefore seems to be once the code is passed to the encoding aspect that it throws a wobbly and adds the slashes
  • 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.