Jump to content

jarvis

Members
  • Posts

    518
  • 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. Thanks again @Barand for your help. Sadly that still doesn't work: <script> $(".gantt").gantt({ navigate: "buttons", scale: "days", source: [[{"name":"Ducks Suite 2","desc":119,"values":{"from":"29-03-2022","to":"02-04-2022","label":"Small ducks (6)"...,"customClass":"ganttBlue"}}]] }); </script> It seems to double wrap the who source with [] However (penny drop moment!), if I revert back to your first snippet: $json_data = json_encode($json); Then amend the code to create the json array: $json_data = [[ 'from' => $row["start_date"], 'to' => $row["end_date"], 'label' => $row['animal']." (".$quantity.")", 'desc' => $row['name']."<br/>".$row['telephone']."<br/>".$row['email'], 'customClass' => $customClass ]]; $json[] = array( 'name' => $itemName, 'desc' => $row["booking_id"], 'values' => $json_data ); That works!!! 😃 I hope that's the correct way to fix it!? Thank you for taking the time to help, it's always very much appreciated!
  2. Thanks @Barand Oddly, that didn't work at all and didn't produce any output This code, partially works. It outputs the table of the chart but no data: <script> $(".gantt").gantt({ navigate: "buttons", scale: "days", source: <?php $json_data = json_encode($json); echo $json_data; ?> }); </script> Checking the source code, I can see (truncated a lot of the inner stuff): <script> $(".gantt").gantt({ navigate: "buttons", scale: "days", source: [{"name":"Ducks Suite 2","desc":119,"values":{"from":"29-03-2022","to":"02-04-2022","label":"Small ducks (6)"...."customClass":"ganttBlue"}}] }); </script> This code works: <script> $(".gantt").gantt({ navigate: "buttons", scale: "days", source: [ <?php $json_data = json_encode($json); #echo $json_data; $i = 0; $len = count($json); foreach( $json as $data ): echo '{'; echo 'name: "'.$data["name"].'",'; echo 'desc: "'.$data["desc"].'",'; echo "values: [{"; echo 'from: "'.$data['values']['from'].'",'; echo 'to: "'.$data['values']['to'].'",'; echo 'label: "'.$data['values']['label'].'",'; echo 'desc: "'.$data['values']['desc'].'",'; echo 'customClass: "'.$data['values']['customClass'].'"'; echo '},]'; if( $i == $len - 1 ): echo '}'; else: echo '},'; endif; endforeach; ?> ], }); </script> This outputs: <script> $(".gantt").gantt({ navigate: "buttons", scale: "days", source: [ {name: "Ducks Suite 2",desc: "119",values: [{from: "29-03-2022",to: "02-04-2022",label: "Small ducks (6)"...,customClass: "ganttBlue"},]}, ], }); </script> It looks like the part values requires the content to be wrapped in [] which the manual code does. The json_encode seems to exclude these - hence the content not fully loading!
  3. Hmm, it's odd. This works: <script> $(".gantt").gantt({ source: [ <?php $i = 0; $len = count($json); foreach( $json as $data ): echo '{'; echo 'name: "'.$data["name"].'",'; echo 'desc: "'.$data["desc"].'",'; echo "values: [{"; echo 'from: "'.$data['values']['from'].'",'; echo 'to: "'.$data['values']['to'].'",'; echo 'label: "'.$data['values']['label'].'",'; echo 'desc: "'.$data['values']['desc'].'",'; echo 'customClass: "'.$data['values']['customClass'].'"'; echo '},]'; if( $i == $len - 1 ): echo '}'; else: echo '},'; endif; endforeach; ?> ], navigate: "buttons", scale: "days" }); </script> But this doesn't: <script> $(".gantt").gantt({ navigate: "buttons", scale: "days", source: <?php $json_data = json_encode($json); echo $json_data; ?> }); </script> I've moved the navigate and scale above source to prevent an issue with the commas but can see why it won't work?
  4. Thanks @Barand I did try that but it returned no results, hence going the manually route. On closer inspection I think it may be to do with the comma when calling it: $(".gantt").gantt({ source: [ <?php $json_data = json_encode($json); echo $json_data; ?> ], navigate: "buttons", scale: "days" }); Also tried: $(".gantt").gantt({ source: <?php $json_data = json_encode($json); echo $json_data; ?> , navigate: "buttons", scale: "days" });
  5. Hi all, I've got a database returning specific data. I'm looping this information and creating an array as follows (this helps grab only the info I need and format any data): $bookings[] = array( 'booking_id' => $post->ID, 'name' => $all_meta_for_user['first_name'][0].' '.$all_meta_for_user['last_name'][0], 'telephone' => $all_meta_for_user['billing_phone'][0], 'email' => $all_meta_for_user['billing_email'][0], 'suite' => get_the_title( $bookingMeta['_booking_product_id'][0] ), 'animal' => get_the_title( $bookingMeta['_booking_resource_id'][0] ), 'quantity' => unserialize($bookingMeta['_booking_persons'][0]), 'order_id' => $order_id_number, 'start_date' => date_format($start_date,"d-m-Y"), 'end_date' => date_format($end_date,"d-m-Y"), ); I'm then grouping the array by suite: // group data by suite (pen) $result = array(); foreach ($bookings as $booking) : $result[$booking['suite']][] = $booking; endforeach; This allows me to display the information in a tabulated format. This is handled by the following code: $json = array(); $count = 0; foreach ($result as $itemName => $rows) : $count++; echo '<tr>'; echo '<td colspan="7"><strong>', $itemName, '</strong></td>'; echo '</tr>'; $customClass = ($count % 2 == 1) ? "ganttRed" : "ganttBlue"; foreach ($rows as $row) : echo '<tr>'; echo '<td>', $row["booking_id"],$customClass. '</td>'; echo "<td>".$row['name']."<br/>".$row['telephone']."<br/>".$row['email']."</td>"; echo "<td>".$row['suite']."<br/>(".$row['animal'].")</td>"; echo "<td>"; foreach ($row['quantity'] as $quantity): echo $quantity; endforeach; echo "</td>"; echo '<td>', $row["order_id"], '</td>'; echo '<td>', $row["start_date"], '</td>'; echo '<td>', $row["end_date"], '</td>'; echo '</tr>'; $json_data = [ 'from' => $row["start_date"], 'to' => $row["end_date"], 'label' => $row['suite']." (".$row['animal'].")", 'desc' => $row['name']."<br/>".$row['telephone']."<br/>".$row['email'], 'customClass' => $customClass ]; $json[] = array( 'name' => $itemName, 'desc' => $row["booking_id"], 'values' => $json_data ); endforeach; endforeach; The final part is creating JSON from the above as this is then used to construct a jQuery Gantt chart. I'm using the following: $i = 0; $len = count($json); foreach( $json as $data ): echo '{'; echo 'name: "'.$data["name"].'",'; echo 'desc: "'.$data["desc"].'",'; echo "values: [{"; echo 'from: "'.$data['values']['from'].'",'; echo 'to: "'.$data['values']['to'].'",'; echo 'label: "'.$data['values']['label'].'",'; echo 'desc: "'.$data['values']['desc'].'",'; echo 'customClass: "'.$data['values']['customClass'].'"'; echo '},]'; if( $i == $len - 1 ): echo '}'; else: echo '},'; endif; endforeach; My question is whether I've massively over complicated this and whether I can achieve what's required with a more streamlined approach? Thanks
  6. Oh dear 😢 That's certainly popped by bubble. I genuinely thought I'd nailed it. I best go revisit the code Thanks @mac_gyver
  7. D'oh! Solved it by casting it to an array: count((array)$_REQUEST['id']))
  8. Good morning, I've the following code: $message = ''; if ('delete' === $table->current_action()) { $message = '<p>' . sprintf(__('Notifications deleted: %d', 'prg_customer_notification'), count($_REQUEST['id'])) . '</p>'; } Which seems to cause a warning of: When I've had similar before, it's been a case of doing something like changing: if (count($_REQUEST['id']) > 0) : To: if (is_countable($_REQUEST['id']) && count($_REQUEST['id']) > 0) : But I can't fathom out how to apply the same principal to the above code. Or have I misunderstood the warning?
  9. Thank you so much @mac_gyver I really appreciate that. I'd been playing around with: $data = array(); foreach($results as $event){ if(isset($event->Year)){ #$data[$event->Year][$event->Month]['ID']= $event->ID; #$data[$event->Year][$event->Month]['Title'] = $event->Title; $data[$event->Year][$event->Month]['Title'] = $event->Title; #$data[$event->Month][]['Month'] = $event->Month; } else { $data[$event->Year] = array($event->Title); } } So I wasn't a million miles away - although your code made it sooo much easier! Thank you once again!
  10. Hi All, Hope you're well! I rather hope someone can help. I've got the following code which queries a database and returns results. I'm then trying to loop the results and group by year, then within a year, group by month. The code works but outputs the following: 2022 April - Title 4 April - Title 3 March - Title 2 2021 December - Title 1 As you can see, if a month has more than one result, it displays the month name twice. What I'd like is: 2022 April - Title 4 - Title 3 March - Title 2 2021 December - Title 1 Here's my code: <?php global $wpdb; $post_type = 'offers'; $post_status = 'publish'; $expiry_date = 'expiry_date'; $results = $wpdb->get_results( $wpdb->prepare(" SELECT P.ID, P.post_title as Title, meta_value as 'Expiry Date', DATE_FORMAT(meta_value, '%Y') as Year, DATE_FORMAT(meta_value, '%m') as Month FROM {$wpdb->prefix}posts AS P LEFT JOIN {$wpdb->prefix}postmeta AS PM on PM.post_id = P.ID WHERE P.post_type = %s and P.post_status = %s and ( meta_key = %s )", $post_type, $post_status, $expiry_date) ); $count_month_map = array(); foreach ($results as $result) : if(array_key_exists($result->Year, $count_month_map)) : array_push($count_month_map[ $result->Year ], $result); else: $count_month_map[ $result->Year ] = Array( $result ); endif; endforeach; $last_year = 0; if( $count_month_map ): foreach ($count_month_map as $year => $month) : ?> <h3><?php echo $year; ?></h3> <?php rsort($month); foreach ($month as $key) : ?> <h4><?php echo $monthName = date('F', mktime(0, 0, 0, $key->Month, 10)); ?></h4> <?php $featured_img_url = get_the_post_thumbnail_url($key->ID, 'thumbnail'); #full if ( ! empty( $featured_img_url ) ): ?> <img src="<?php echo esc_url($featured_img_url); ?>" class="img-fluid" /> <?php endif; ?> <p><a href="<?php echo get_permalink($key->ID); ?>" title="<?php echo $key->Title; ?>"><?php echo $key->Title; ?></a></p> <?php endforeach; endforeach; endif; ?> I'm not sure if I've approached this correctly, so any help is very much appreciated Thank you
  11. Because of the semi-colon at the end of each declaration and those being declared inside $data. You would need to move them outside like so: $content_slug = ucfirst($page['content_slug']); $content_title = ucfirst($page['content_title']); $data = [ 'title' => "{$content_slug} ({$content_title}) ", 'meta.description' => $description, 'page' => $page, ]; return $app->render($template, $data); }
  12. Is it not possible to do something like: $content_slug = ucfirst($page['content_slug']); $content_title = ucfirst($page['content_title']); 'title' => "{$content_slug} ({$content_title})", Maybe a better option but I'd convert them first, then insert them.
  13. Am no expert but perhaps something more like: <?php $looking = isset($_GET['title']) || isset($_GET['author']); $title = isset($_GET['title']) ? $_GET['title'] : 'No title set'; $author = isset($_GET['author']) ? $_GET['author'] : 'No author set'; ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Bookstore</title> </head> <body> <p>The book you're looking for is:</p> <ul> <li><strong>Title</strong>: <?php echo $title; ?></li> <li><strong>Author</strong>: <?php echo $author; ?></li> </ul> </body> </html> Others with way more experience may be able to improve further but that should at the very least get you up and running!
  14. You have errors in your code: <?php $looking = isset($_GET['title']) || isset($_GET['author']); ?> <!doctype html> <html lang = "en"> <head> <meta charset ="UTF-8"> <title>Bookstore</title> </head> <body> <p>you looking <?php echo (int) $looking; ?> </p> <p>The book you are looking for is </p> <ul> <li><b>Title</b>: <?php echo $_get['title']; ?></li> <li><b>Author</b> <?php echo $_get['author']; ?></li> </ul> </body> </html> Is your debugging/error checking on? Once I fixed the errors in line 2 and 15, it displays but still flags the following: Notice: Undefined variable: _get in index.php on line 14 Notice: Undefined variable: _get in index.php on line 15 Your code also seemed a tad scruffy given it was a copy/paste from a book!
  15. Many thanks for your time! I'll have a play and see what I can do - thank you for the pointers...
×
×
  • 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.