Jump to content

codebyren

Members
  • Posts

    156
  • Joined

  • Last visited

Posts posted by codebyren

  1. 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/

     

  2. 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...

     

  3. 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>
    
  4. 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.

     

     

  5. 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);
    }
    

  6. 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;
    ?>
    
  7. 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"
    
  8. 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)

  9. 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();
            }
        }
    }
    
  10. 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.

  11. 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.

     

  12. 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.

  13. You should look into and use "relative paths" (or URLs).  Then you can provide the location of the background image relative to the location of the CSS file.  Something like:

     

    url('../../images/image.jpg')
    

     

    The above (for example) would traverse two levels up from where the CSS file is located and then into an "images" subdirectory to find image.jpg

  14. I've never worked with (or heard of) Servebase but I suspect you need to use something like cURL to do the Response Request part of it - and then present only the "second form" to the end-user. Upon submitting this, they will be redirected to the payment gateway to continue payment.

     

    For a decent tutorial on cURL, you can check out this one at Nettuts.

  15. You can get the first and last day of the current month pretty easily using the date() function. Something like:

     

    <?php
    $first_day = date('Y-m-\0\1'); # force "01" as the day here.
    $last_day = date('Y-m-t'); # the "t" is for the number of days in the given month (i.e. always the last day of the month)
    
    $cart = "select * from tbl_cart where pdate between '$first_day' and '$last_day' and uid = '".$_SESSION['id']."'";
    ?>
    

     

    Hope I didn't overlook anything...

  16. Hmm. . . if you are just going to set $dimension on each loop - no need to use the ternary operator and make the PHP processor do more work by doing a comparison check. Just set the value to 200 before the loop and to 100 at the end of each iteration.

     

    Schooled. It's obvious now that you point it out. Thanks.

  17. Set a counter outside of your loop and increment it within your loop. If the counter is equal to its starting value then image = 200x200, otherwise image = 100x100.

     

    $getSize = mysql_query("SELECT image_location FROM size_chart WHERE prod_size_id = $GET_ID");
    $i = 1;
    while($chart = mysql_fetch_array($getSize))  {
       $dimension = ($i == 1) ? '200px' : '100px';    
    ?>
    <a href="<?php echo $chart ?>"><img src="<?php echo $chart ?>" width="<?php echo $dimension; ?>" height="<?php echo $dimension; ?>" /></a>
    <?php
    $i++;
    }
    ?>
    

  18. It's not very clear how you are planning to store the values in the database and I can't see exactly which form fields map to which database fields. If each dynamic line should be a separate row in the "gc_dioptry" table then you could try something like this:

     

    
    // Collect desired post arrays
    $from = $this->input->post('from');
    $to = $this->input->post('to');
    $step = $this->input->post('step');
    // etc.
    
    $rows = array();  # we'll store each row in this array
    
    // Setup a counter for looping through post arrays
    // If there are x items in one post array (e.g. $from) then the others *should* contain the same number
    $row_count = count($from);
    
    for ($i=0; $i < $row_count; $i++) { 
       $rows[] = array(
           'produkt' => '???',
           'from' => $from[$i],
           'to' => $to[$i],
           'step' => $step[$i],
           'dependancy' => '???',
           'value' => '???',
       );
    }
    
    $this->db->insert_batch('gc_dioptry', $rows);
    

     

    You could add some validation like checking that your post values are actually arrays and also check whether array keys ($i in this example) exist before using them. This will prevent errors being thrown.

  19. Firstly, the delimiters look fine - are you sure the "no ending delimiter" error is the one you are still getting?

     

    Secondly, preg_match will only return FALSE if $eml does NOT match the pattern - so your IF statement isn't quite right as it will die with the "invalid email address" message for emails that match the pattern. You could negate the condition to fix this:

     

    <?php
    if ( ! preg_match($pattern, $subject)) {
    // no match...
    }
    ?>
    

     

    Finally, you could use php's filter_var function for email validation if your server has PHP 5 >= 5.2.0:

     

    <?php
    if (filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)) {
    // email appears ok...
    }
    ?>
    

  20. Your entire IF statement needs to be within Parentheses (brackets). So, something like:

     

    if ($Hoff == 'Nelspruit' || $Hoff == 'Hoedspruit' || $Hoff == 'Klaserie' || $Hoff == 'Whatever else') {
    $addon = $addon+2;
    }
    else {
    $addon = $addon -100;
    }
    

     

    Should do the trick...

  21. The xml looks like it could contain any number of <channel> entries. Each of these channels has its own title, description etc. as well as any number of <item> entries which also have their own title, description etc.

     

    So, going by the code you have so far, it might read better as:

     

    <?php foreach ($xml as $channel) : ?>

     

    Then you could access the CHANNEL info like this:

     

    <?php echo $channel->title; ?>
    <?php echo $channel->description; ?>
    etc...
    

     

    You could then cycle through each $channel's <item> entries:

     

    <?php foreach ($channel->item as $item) : ?>

     

    After which you could access the ITEM info like this:

     

    <?php echo $item->title; ?>
    <?php echo $item->description; ?>
    etc...
    

     

    Hope that clears things up a little.

×
×
  • 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.