OpenCart 1.5.x.x ajax随机值

时间:2017-11-16 14:00:50

标签: php ajax opencart-module page-caching openca

我有动态块,可以随机排序显示和隐藏表中的产品。但是当现金页面处于活动状态时,这部分页面会显示产品并仅显示来自查询的第一个产品...我不明白我怎样才能使其与此效果一起工作并在随机存储上显示10个产品... 查询

$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);

返回$ query-> row;

与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>

和我的功能

    $(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 个答案:

答案 0 :(得分:1)

name和desc应该是一个数组

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'];
}

和这个

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

我假设你的json.length是complex.length同样的东西