Jump to content


  • Posts

  • Joined

  • Last visited

About codebyren

  • Birthday 04/19/1985

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    New Zealand

codebyren's Achievements


Member (2/5)



  1. If the divs are siblings in the HTML then you can use the next() or nextall() method - something like this: $('.tricks_head').click(function() { var $tricks_head = $(this); $tricks_head.next('.trick').toggle('slow'); }); Updated demo here: http://jsfiddle.net/codebyren/AqSp2/1/
  2. Do you have control of the HTML mark-up? If so, you could try something like this: <div class="tricks_head"> <div class="trick"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates, totam. </div> </div> <div class="tricks_head"> <div class="trick"> Ratione, maiores labore nulla atque recusandae repellendus est. Iusto, ut. </div> </div> With non-numeric classes for the divs, the JavaScript is fairly simple: $('.tricks_head').click(function() { var $tricks_head = $(this); $tricks_head.find('.trick').toggle('slow'); }); You can see a working demo here: http://jsfiddle.net/codebyren/AqSp2/
  3. As long as you produce valid/usable JavaScript with your PHP output, you should be ok. If, like most people, you have JavaScript separate from your PHP and HTML then you could build an array of image URLs in PHP (after fetching from mysql) and then store this array as a JSON encoded data attribute. Something like this: Build the array... <?php $images = array('http://placehold.it/100x150.png', 'http://placehold.it/200x200.png', 'http://placehold.it/150x150.png', 'http://placehold.it/300x100.png'); ?> Add it to the markup (note the single quotes surrounding the data-image-list value)... <div id="product" data-image-list='<?php echo json_encode($images); ?>'> <ul id="controls"> <li><a href="#" data-action="prev">Prev Image</a></li> <li><a href="#" data-action="next">Next Image</a></li> </ul> <div id="imagediv"> <img src="http://placehold.it/100x150.png" alt="" /> </div> <p>This is some information about the product</p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A, itaque, eveniet quae sunt aperiam beatae!</p> </div> Then access the image array and use it in your JavaScript... $(document).ready(function() { var images = $('#product').data('imageList'); // Now you should have an array of images to work with... // ... }); Hope that helps...
  4. I'm sure there is an existing slider solution that meets your requirements. I haven't tried it myself but Google found Sudo Slider with a dynamic height/width example here: http://webbies.dk/assets/files/SudoSlider/package/demos/autowidth%20centered.html As for your idea to manually change the image in a div, I've written a jsfiddle (code below too) so you can see how this could be done in jQuery. It might be a little involved if you have little or no jQuery/JavaScript experience but you'll have to hit the documentation sometime... <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Image Switch</title> </head> <body> <div id="container"> <div id="product"> <ul id="controls"> <li><a href="#" data-action="prev">Previous</a></li> <li><a href="#" data-action="next">Next</a></li> </ul> <div id="imagediv"> <img src="http://placehold.it/100x150.png" alt=""> </div> <p>This is some information about the product</p> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. A, itaque, eveniet quae sunt aperiam beatae!</p> </div> </div> <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { // The images that we want to cycle through... var images = ['http://placehold.it/100x150.png', 'http://placehold.it/200x200.png', 'http://placehold.it/150x150.png', 'http://placehold.it/300x100.png']; // The links that cycle the images var $controls = $('#controls a'); // The image element var $image = $('#imagediv').find('img:first'); $controls.click(function(e) { // The prev/next links don't actually go anywhere... e.preventDefault(); // If for some reason there are no images... if ( ! images.length) return false; // The link that's just been clicked var $link = $(this); // Which direction to cycle the images var action = $link.data('action') == 'next' ? 'next' : 'prev'; // Find the position of our currently displayed image in the list of possible images var image_url = $image.attr('src'); var image_index = $.inArray(image_url, images); // $.inArray returns -1 if the item doesn't exist in the array to search // Calculate the position of the previous and next images relative to current image in the images array // (accounting for when the user hits "next" on the last image or "previous" on first image) var next_index = (image_index + 1 <= images.length - 1) ? image_index + 1 : 0; var prev_index = (image_index - 1 >= 0) ? image_index - 1 : images.length - 1; // Find the new image's URL using the images array var new_image = (action == 'next') ? images[next_index] : images[prev_index]; // Update the image element with the new image's URL $image.attr('src', new_image); }); }); </script> </body> </html>
  5. Firstly, you are trying to access an attribute called "farm" as "farm-id" and "server" as "server-id". You probably want : $set['farm'] and not: $set{farm-id} Likewise with server vs server-id. Then, note the presence of the quotes wrapping 'farm-id' which stops PHP from treating "farm" and "id" as separate constants - which is what caused your "Use of undefined constant XYZ" errors.
  6. Browser detection can be tricky/unreliable and is probably not recommended. That being said, you could start with something like the code below. I'm not convinced it's perfect but it worked in a quick test of Chrome and FireFox: if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1) { document.addEventListener('DOMMouseScroll', function(e){ e.stopPropagation(); e.preventDefault(); e.cancelBubble = true; }, false); }
  7. If you're going to pass the URL to your PHP code via AJAX, you will probably need something like this: $.ajax({ url: "ajax-category.php", data: {url: pagination_url}, // note the key/value pairs type: "POST", dataType: "html" // etc. }); Now the URL should be available in $_POST['url'] but you will still need to extract the variables (parameters) from it. Two functions, namely parse_url followed by parse_str should help with this. Without any error checking, it might look like this: <?php $url = $_POST['url']; // Break the URL into its parts $url_parts = parse_url($url); // Convert the query part of the URL into an array of parameters parse_str($url_parts['query'], $params); print_r($params); // Array ( [filterCat] => 2 => 3 ) exit; ?>
  8. The datepicker method is invoked as datepicker() regardless of the ID or selector that you pass to it. For example: $('#datepicker1234657').datepicker(); // good - run datepicker on html element with ID "datepicker1234567" $('#datepicker1').datepicker1(); // BAD - there is no method called datepicker1 That should be enough to get you going. As you learn more about jQuery (and the selectors it can use), you'll find ways to specify multiple elements to act upon: $('#datepicker, #datepicker1').datepicker(); // run datepicker on HTML elements with ID "datepicker" or "datepicker1" $('.datepicker').datepicker(); // run datepicker on all HTML elements with a class of "datepicker"
  9. Yes, an id on an element must be unique. You would be better off adding a 'datepicker' class to the inputs and then using that as the selector in jQuery. $('.datepicker').datepicker();
  10. Just think of the datepicker field as an ordinary input. It still needs to be thrown into a <form> and submitted to the server as normal if you want to do anything with its value.
  11. The jQuery datepicker just enhances an existing input field and enables the user to easily enter a valid date. So, In terms of PHP, you just process the input as if there were no datepicker at all. The end requirement is the same: the posted input must contain a valid date regardless of datepicker presence. Or are you having problems getting the datepicker itself to work? (which is Javacript and not PHP related)
  12. You can extend the form validation library to make any errors accessible as an array in your controller. // MY_Form_validation.php (goes in application/libraries) class MY_Form_validation extends CI_Form_validation { public function error_array() { return $this->_error_array; } } Then you can access any errors in your controller and do whatever you want with them. class Tests extends CI_Controller { // Constructor etc. here // ... public function something() { $this->load->library('form_validation'); // Set validation rules, do other stuff, whatever. if ($this->form_validation->run() === FALSE) { $errors = $this->form_validation->error_array(); } } }
  13. You can use the BETWEEN operator but you will still need to do some date manipulation. Something like: <?php $input_date = '2013-05-10'; # just a random date to test with $time = strtotime($input_date); $first_day_of_month = date('Y-m-01', $time); $last_day_of_month = date('Y-m-t', $time); $query = "SELECT `actitle` FROM `activities` WHERE `acdate` BETWEEN '$first_day_of_month' AND '$last_day_of_month'"; ?> Hopefully that makes sense to you.
  14. There is a lot of repeated code for dealing with DB queries. You could try something like this: <?php // Fetch locations, responsibilities and types in one go... $locations = $responsibilities = $types = array(); $query = "SELECT `Location`, `Responsibility`, `Type` FROM `admin`"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $locations[] = $row['Location']; $responsibilities[] = $row['Responsibility']; $types[] = $row['Type']; } // Maybe hack in some last-minute sorting... sort($locations); sort($responsibilities); sort($types); ?> <!-- A sample drop-down menu population --> <label for="location">Location: </label> <select name="location" id="location"> <option value="">Please Select</option> <?php foreach ($locations as $location) : ?> <option value="<?php echo $location; ?>"><?php echo $location; ?></option> <?php endforeach; ?> </select> It's a personal preference I guess, but that looks pretty clean.
  15. The issue here is that your echo statement in the foreach loop includes the opening and closing table structure - so the opening and closing table tags are being rendered for each iteration of your array. What you want is to only loop through your array when creating rows in the actual table. Something like: <?php $superheroes = array('Superman' => 'Clark Kent', 'Spiderman' => 'Peter Parker', 'Batman' => 'Bruce Wayne'); ?> <table> <thead> <tr> <th>Superhero</th> <th>Secret Identity</th> </tr> <tbody> <?php foreach ($superheroes as $hero => $identity) : ?> <tr> <td><?php echo $hero; ?></td> <td><?php echo $identity; ?></td> </tr> <?php endforeach; ?> </tbody> </thead> </table> Notice how only the table row creation falls inside the foreach loop.
  • 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.