Jump to content

jarvis

Members
  • Posts

    537
  • 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)

3

Reputation

2

Community Answers

  1. 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
  2. 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!?
  3. Literally: $json[] = array( 'name' => $itemName, 'desc' => 'Booking #'.$row["booking_id"], 'values' => $data ); $itemName = ''; That works! Thanks, pretty obvious really
  4. 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).
  5. 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?
  6. 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
  7. 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
  8. 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
  9. 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!
  10. 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!
  11. @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
  12. 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
  13. Thanks @mac_gyver I see RE the JSON_UNESCAPED_SLASHES If I simply set the code to: $pin_color = '#f76458'; $icon_color = '#000'; $icon = "\u{f57f}"; Then the return data is: "pin_color":"#f76458","icon_color":"#000","icon":"\uf57f" Which works. If I amend the code to: if (!empty($child_icon)) : $pin_color = $child_pin_colour; $icon_color = $child_icon_colour; $icon = "\u{f57f}"; elseif (!empty($parent_icon)) : $pin_color = $parent_pin_colour; $icon_color = $parent_icon_colour; $icon = "\u{f57f}"; else: $pin_color = '#f76458'; $icon_color = '#000'; $icon = "\u{f57f}"; endif; This also works, showing the different pin/marker colours and the same icon. It just seems to be when getting the value from the DB for $icon it doesn't work.
  14. Thanks @mac_gyver I've tried both: $json_data = json_encode($json,JSON_UNESCAPED_UNICODE); And $json_data = json_encode($json,JSON_UNESCAPED_SLASHES); In both instances, it still seems to return: "pin_color":"#dd9933","icon_color":"#ffffff","icon":"\\f192" This is before I even try to do anything to get the value into the format I need (\u{f192})
  15. Thanks @ginerjm Apologies, wasn't doubting your code at all. Ok, so the database stores the data like so: { "style" : "regular", "id" : "circle-dot", "label" : "Circle dot", "unicode" : "f192" } If I output (echo) the unicode value (which is the one I need), it always returns the value as: \f192 If I check the JSON being created, the value already changes to: "pin_color":"#dd9933","icon_color":"#ffffff","icon":"\\f192" I only have the code as per the above, so something is clearly causing an issue. With regards to the '$child_icon anywhere else but the very first line of your example', this is fine. Basically, the code has 3 levels it checks through: child, parent then default This is a Wordpress site you see and the values are stored against taxonomies. It checks the child value, if it has a value it's displayed, if it's empty, it checks the parent value and displays it, if that's also empty, it displays the default. Only the initial code needs this, as it determines which value is passed through the JSON and therefore displayed on the map - I possibly haven't explained that very well!
×
×
  • 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.