Jump to content

jarvis

Members
  • Posts

    543
  • Joined

  • Last visited

Everything posted by jarvis

  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...
  16. 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?!
  17. 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
  18. 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"; } ?>
  19. 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>
  20. 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
  21. 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.
  22. 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
  23. 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
  24. Hi @Gunnyk Would something like this be a good starting point?
  25. Hi @BookSense I always come here to learn and ask others for advice. I'm always asked to show my code, what I've tried, explain why things don't work, what errors I get, what debugging I've done. etc. You mentioned you've downloaded loads of email scripts but none work. Why? What errors do you get? What did you try? You didn't share anything here for others to help. If they ALL failed, then maybe it's more server related!? I get embarrassed asking for help at times, especially when I simply don't 'get it' but it's the only way to learn and sometimes I can sense the frustration in the people trying to point out the glaringly obvious. I'm constantly trying to learn and improve. It does feel despite what appears to have been a truly terrible day, you may need to try harder! You mentioned you 'redeveloped all my other front-end software ' surely that's pretty skilled, so seems odd you can't sort the form!? Below is a very simple script - it may work, it may not. Contact Page: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Contact Us</title> </head> <body> <form method="post" name="contact" action="contact.php"> Your Name: <input type="text" name="name"> Email Address: <input type="text" name="email"> Message: <textarea name="message"></textarea> <input type="submit" value="Submit"> </form> <script language="JavaScript"> var validate = new Validator("contact"); validate.addValidation("name","req","Please provide your name"); validate.addValidation("email","req","Please provide your email"); validate.addValidation("email","email","Please enter a valid email address"); </script> </body> </html> contact.php $errors = ''; $myemail = 'yourname@website.com';//<-----Put Your email address here. if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) { $errors .= "\n Error: all fields are required"; } $name = $_POST['name']; $email_address = $_POST['email']; $message = $_POST['message']; if (!preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; } if( empty($errors)) { $to = $myemail; $email_subject = "Contact form submission: $name"; $email_body = "You have received a new message. ". " Here are the details:\n Name: $name \n ". "Email: $email_address\n Message \n $message"; $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); //redirect to the 'thank you' page header('Location: thank-you.htm'); } thank-you.htm: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Thank You</title> </head> <body> Thanks </body> </html> Maybe try that, if it doesn't work, try debugging it to find out why. If it's not got enough data capture fields, hopefully, it's a good starting point to develop!
×
×
  • 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.