jquery image not loading from array in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelicdevil
    New Member
    • Apr 2009
    • 116

    jquery image not loading from array in php

    i have the jquery loading the image gallery part as follows

    Code:
    <script type="text/javascript">
    
    function mycarousel_itemLoadCallback(carousel, state)
    {
        // Check if the requested items already exist
        if (carousel.has(carousel.first, carousel.last)) {
            return;
        }
    
        jQuery.get(
            'dynamic_ajax_php.php',
            {
                first: carousel.first,
                last: carousel.last
            },
            function(xml) {
                mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, xml);
            },
            'xml'
        );
    };
    
    function mycarousel_itemAddCallback(carousel, first, last, xml)
    {
        // Set the size of the carousel
        carousel.size(parseInt(jQuery('total', xml).text()));
    
        jQuery('image', xml).each(function(i) {
            carousel.add(first + i, mycarousel_getItemHTML(jQuery(this).text()));
        });
    };
    
    /**
     * Item html creation helper.
     */
    function mycarousel_getItemHTML(id,url)
    {
        return '<img src="' + url + '" width="75" height="75" alt="" />';
    };
    
    jQuery(document).ready(function() {
        jQuery('#mycarousel').jcarousel({
            // Uncomment the following option if you want items
            // which are outside the visible range to be removed
            // from the DOM.
            // Useful for carousels with MANY items.
    
            // itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
            itemLoadCallback: mycarousel_itemLoadCallback
        });
    });
    
    </script>
    i want that the images should be loaded from the array in php holding the location of the images . my php script is as follows

    Code:
    <?php
    
    // Array 
    
    
    $total = -1;
    
    $images = array();
    $query = "SELECT images_list.loc FROM images_list ";
    	$result = mysql_query($query);
    	confirm_query($result);
    	$images[]=" ";
            while ($record = mysql_fetch_assoc($result)) {
              $images[] = $record['loc'] ;	
                              
              }
              $total    = count($images); 
              $selected = array_slice($images, $first, $length);
    
    // ---
    
    header('Content-Type: text/xml');
    
    echo '<data>';
    
    echo '  <total>' . $total . '</total>';
    
    foreach ($selected as $img) {
        echo '  <image>' . $img . '</image>';
    }
    
    echo '</data>';
    
    
    
    function confirm_query($r) {
    		if (!$r) {
    			die("Database query failed: " . mysql_error());
    		}
    	}
    ?>

    but the images don't load into the gallery....some one plz help
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    I didnt read your code. it wont take me anywhere, I would rather suggest you something.

    say x.php would be called by ajax request, and it would return an array to the client. here how you can achieve it:

    in x.php
    Code:
    <?php
    $a[0]='data1';
    $a[1]='data2';
    $a[3]='data3';
    $a[4]='data4';
    echo "<script>";
    echo "var jarray=new Array()";
    for($i=0;$i<count($a);$i++)
    {
     echo "jarray[".$i."]='".$a[$i]."'";
    }
    echo "</script>";
    ?>
    in jquery success
    Code:
    $("#some_hidden_div").html(returned_text_by_PHP);
    
    //codes to access jarray
    at this stage you have the array in a usable status,

    Comment

    Working...