Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by jarvis

  1. Hi, I hope someone can help. The following code combines jQuery DataTables and Google Maps to create filtering. This works perfectly. What I'm trying to do, due to the volume of data is then include clustering. I've got the relevant Clustering incude: <script src="https://unpkg.com/@googlemaps/markerclusterer/dist/index.min.js"></script> This is the full code to build the table/map: var locations = <?php echo $json_data; ?> $(document).ready(function () { // Initialize empty map instance var maplace = new Maplace({ shared: { zoom: 16 }, controls_on_map: false, styles: { 'Minimal': [{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"labels.text.fill","stylers":[{"color":"#444444"}]},{"featureType":"landscape","elementType":"all","stylers":[{"color":"#f2f2f2"}]},{"featureType":"poi","elementType":"geometry.fill","stylers":[{"saturation":"-100"},{"lightness":"57"}]},{"featureType":"poi","elementType":"geometry.stroke","stylers":[{"lightness":"1"}]},{"featureType":"poi","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"road","elementType":"all","stylers":[{"saturation":-100},{"lightness":45}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.arterial","elementType":"labels.icon","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"transit","elementType":"labels","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels.text","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels.text.fill","stylers":[{"visibility":"off"},{"color":"#484848"}]},{"featureType":"transit","elementType":"labels.text.stroke","stylers":[{"visibility":"off"}]},{"featureType":"transit","elementType":"labels.icon","stylers":[{"visibility":"on"}]},{"featureType":"transit.station.bus","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit.station.bus","elementType":"labels.text.fill","stylers":[{"saturation":"0"},{"lightness":"0"},{"gamma":"1.00"},{"weight":"1"}]},{"featureType":"transit.station.bus","elementType":"labels.icon","stylers":[{"saturation":"-100"},{"weight":"1"},{"lightness":"0"}]},{"featureType":"transit.station.rail","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit.station.rail","elementType":"labels.text.fill","stylers":[{"gamma":"1"},{"lightness":"40"}]},{"featureType":"transit.station.rail","elementType":"labels.icon","stylers":[{"saturation":"-100"},{"lightness":"30"}]},{"featureType":"water","elementType":"all","stylers":[{"color":"#d2d2d2"},{"visibility":"on"}]}] } }).Load(); //new markerClusterer.MarkerClusterer({ locations, maplace }); // Initialize DataTable var myTable = $('#mytable').DataTable({ data: locations, pageLength: 10, columns: [ {data: 'title', title: 'City'}, {data: 'lat', title: 'Latitude'}, {data: 'lon', title: 'Longitude'}, ], columnDefs: [ {targets: [0], width: '33%'}, {targets: [1], width: '33%'}, {targets: [2], width: '33%'}, ], // When the table is redrawn, update the map with the visible rows drawCallback: function(settings) { var api = this.api(); // Clear all markers when table is redrawn var markers = { 'locations': [] }; // Page: all / search: applied - makes sure all pages are used with the applied filter api.rows({page: 'all', search: 'applied'}).every(function(rowIdx, tableLoop, rowLoop) { var data = this.data(); var loc = { 'lat': data.lat, 'lon': data.lon, 'html': data.html, 'icon': data.icon }; markers.locations.push(loc); //new MarkerClusterer({ markers, maplace }); var row = this.node(); $(row).removeClass (function (index, css) { return (css.match (/\brow-\d+/g) || []).join(' '); }); $(row).addClass('row-'+ rowLoop); }); // Load the map maplace.Load({ locations: markers.locations }); } }); // Add per column filters yadcf.init(myTable, [ { column_number: 0 } ]); // Add event listener clicking on table and showing on map $('#mytable tbody').on('click', '.sorting_1', function () { var tr = $(this).closest('tr'); var row = myTable.row(tr); // This is our class-populated row number var idx = Number(tr.attr('class').match(/(?:row-)(\d+)/)[1]) + 1; // Zoom to clicked record on map maplace.ViewOnMap(idx); }); // Cluster the markers new markerClusterer.MarkerClusterer({ locations, maplace }); }); But I can't see how to get the clustering to work? I thought I'd be ok so include it and reference the map/markers. Perhaps it's where I've included the call? But I thought being the last part on the script would be the right way to go about it?
  2. Hi All, Am hoping someone can help! I have a table on my page which has multiple rows. Each row has a button, clicking the button triggers a modal pop up (Bootstrap). Within the modal is various details and a gallery. What I'm trying to do, is get the gallery to run as a carousel using Slick Slider. My ajax function is below: function fetch_post_data(post_id,vids) { var action = 'fetch_post_data'; $.ajax({ url: blog.ajaxurl, method: "POST", data: { action:action, post_id:post_id, vids:vids}, success: function(data) { $('#productModal').modal('show'); $('#post_detail').html(data); } }); } Now, using the following code, I can get the slick slider carousel to work once the modal initially opens: $('.modal').on('shown.bs.modal', function () { $('.slider-class').slick(); $('.wrap-modal-slider').addClass('open'); }); The issue I'm having, is when you scroll to the next modal (hence using Ajax), the carousel won't run. I'm guessing, I need to somehow merge the above function into the success: function(data){} code. However, I simply can't get it to work. Absolutely any help here would be ace! Thanks
  3. 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!
  4. 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!
  5. 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?
  6. 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" });
  7. 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
  8. Oh dear 😢 That's certainly popped by bubble. I genuinely thought I'd nailed it. I best go revisit the code Thanks @mac_gyver
  9. D'oh! Solved it by casting it to an array: count((array)$_REQUEST['id']))
  10. 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?
  11. 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!
  12. 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
  13. 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); }
  14. 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.
  15. 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!
  16. 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!
  17. Many thanks for your time! I'll have a play and see what I can do - thank you for the pointers...
  18. Thanks @requinix The href in the A tag already has href="#tab-reviews" This is to then jump down to the TAB section whereby the code above kicks in and opens the specific TAB. So I can't quite see how to combine the two and go the TAB section, open the specific TAB and then scroll to the section within the TAB Or am I missing something?!
  19. Morning All, I've a link on a page, which when clicked needs to open a specific TAB. The code for this works and can be seen below: jQuery(document).ready(function($){ $('a.jump-to-tab').click(function(e){ e.preventDefault(); var tabhash = $(this).attr("href"); //var tabli = 'li.' + tabhash.substring(1); var tabli = tabhash.substring(1); var tabpanel = '.panel' + tabhash; $(".wc-tabs li").each(function() { if ( $(this).hasClass("active") ) { $(this).removeClass("active"); } }); //$(tabli).addClass("active"); $('[aria-controls="'+tabli+'"]').addClass("active"); $(".woocommerce-tabs .panel").css("display","none"); $(tabpanel).css("display","block"); //$('html,body').animate({scrollTop:$(tabpanel).offset().top}, 750); if (navigator.userAgent.match(/(iPod|iPhone|iPad|Android)/)) { document.getElementById("tab-reviews").scrollIntoView(); }else{ $('html,body').animate({scrollTop:$(tabpanel).offset().top}, 750); } }); }); Ideally, what I'd like to do, is once the TAB is open, to open at a specific point i.e. where a piece of content has a specific ID, in this case #commentform I've looked around but can't seem to see anything and wonder if this is possible? Many thanks in advanced
  20. Using Bootstrap 4 cards, something like: <?php require "database/dbconfig.php"; //include_once __DIR__.'/core-php-admin/database/dbconfig.php'; $query = "SELECT * FROM users"; $query_run = mysqli_query($connection, $query); if (mysqli_num_rows($query_run) >0){ ?> <div class="container py-5"> <div class="row"> <?php foreach ($query_run as $row){ ?> <div class="col-4"> <div class="card"> <img class="card-img-top img-fluid" src="//placehold.it/500x200" alt="Card image cap"> <div class="card-block"> <h4 class="card-title">Card title</h4> <p class="card-text">Card body</p> </div><!-- /card-block --> <div class="card-footer"> Card footer </div><!-- /card-footer --> </div><!-- /card --> </div><!-- /col-4 --> <?php } ?> </div><!-- /row --> </div><!-- /container --> <?php } else { echo "No record found"; } ?>
  21. I think you would need something more like: <?php if (isset($_GET['sayfa'])) { $page_no = $_GET['sayfa']; } else { $page_no = 1; } $no_per_page = 10; $offset = ($page_no-1) * $no_per_page; $total_pages = "SELECT COUNT(*) FROM icerik"; $result = mysqli_query($conn,$total_pages); $total_rows = mysqli_fetch_array($result)[0]; $total_pages = ceil($total_rows / $no_per_page); $sql = "SELECT * FROM icerik LIMIT $offset, $no_per_page"; $result = mysqli_query($conn,$sql); while($row = mysqli_fetch_array($result)){ //whatever you need to go here } mysqli_close($conn); ?> <ul> <li><a href="index.php?sayfa=1">First Page</a></li> <li class="<?php if($page_no <= 1){ echo 'disabled'; } ?>"> <a href="index.php<?php if($page_no <= 1){ echo '#'; } else { echo "?sayfa=".($page_no - 1); } ?>">Previous Page</a> </li> <li class="<?php if($page_no >= $total_pages){ echo 'disabled'; } ?>"> <a href="index.php<?php if($page_no >= $total_pages){ echo '#'; } else { echo "?sayfa=".($page_no + 1); } ?>">Next Page</a> </li> <li><a href="index.php?sayfa=<?php echo $total_pages; ?>">Last Page</a></li> </ul>
  22. It looks like row 1 is called within your code by this line: <p><?php require "./oggi.php";?></p> So just move that below the closing </ul> Like so: <div class="container section" id="afterHeader"> <div class="row"> <div class="tabs movies"> <a class="style1">1^ SETTIMANA</a> <ul> <li><a href="#thu">GIO</a></li> <li><a href="#fri">VEN</a></li> <li><a href="#sat">SAB</a></li> <li><a href="#sun">DOM</a></li> <li><a href="#mon">LUN</a></li> <li><a href="#tue">MAR</a></li> <li><a href="#wed">MER</a></li> </ul> <p><?php require "./oggi.php";?></p> That will then swap line 1 and 2 of your image over
  23. Thanks @Barand - I didn't wish to speak out of term or be incorrect! But does help the post author as I guess some fields maybe numeric.
  24. I could possibly be wrong, but worth checking whether: $query = "insert into Borrowedbooks(uid,bid,borroweddate) values('$uid','$bid','$bdate')"; Just needs to be: $query = "INSERT INTO Borrowedbooks (uid, bid, borroweddate) VALUES ($uid, $bid, $bdate)"; I don't believe you need the single quotes around the variables you're adding. Worth tidying your code too, makes it easier to read and spot issues
  25. Should line 43 not be: if ($row[0] > 0){ Also you're missing a closing } that would pair line 29 but could be a copy/paste error
  • 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.