duanletao9487 2017-11-16 14:00
浏览 30
已采纳

OpenCart 1.5.x.x ajax随机值

I have dynamic block with show and hide products from table on random sort. But when the cash page is active, this part of page stom showing products and show only first product from query ... i do not understand how can i make it work with this effect and show 10 product on random soring ... the query

$sql = "SELECT * FROM " . DB_PREFIX . "product";
$sql .= " WHERE sp_id = ".$id." AND show=1";
$sql .= " ORDER BY shop_id  asc";
$query = $this->db->query($sql);

return $query->row;

and part with ajax :

 <div id="content" class="group">
   <div id="backItem">
     <div id="footerItemContent">
     </div>
     <div id="footerItemDivider">-</div>
       <div id="footerItemCustomer">...</div>
       </div>
     </div>
   </div>
</div>

and my function

    $(document).ready(function() {
var products = function() {

    for ( var i = 0; i < complex.length; i++ ) {
        var name = complex[i]['pr_name'];
        var desc = complex[i]['pr_text'];
    }

var i = 0;
var fnchange = function() {
    $('#footerItemContent').animate({'opacity': 0}, 2000, function () {
        $(this).text(desc);
    }).animate({'opacity': 1}, 2500);
    $('#footerItemCustomer').animate({'opacity': 0}, 2000, function () {
        $(this).text(name);
    }).animate({'opacity': 1}, 2500);
    if( ++i < json.length ){
        setTimeout(fnchange, 10000);
    } else {
        i = 0;
        setTimeout(fnchange, 10000);
    }
};
setTimeout(fnchange, 1);
};
setTimeout(feedbacks,1);
  • 写回答

1条回答 默认 最新

  • dqef7931 2017-11-17 10:06
    关注

    the name and desc should be an array

    var names = new Array();
    var desc = new Array();
    for ( var i = 0; i < complex.length; i++ ) {
        names[i] = complex[i]['pr_name'];
        desc[i] = complex[i]['pr_text'];
    }
    

    and this

    $(this).text(name[i]);
    $(this).text(desc[i]);
    

    I assume your json.length is the complex.length as the same thing

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?