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

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

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭