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

图片转代码服务由CSDN问答提供 功能建议

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

  $ sql =“SELECT * FROM”。  DB_PREFIX。  “product”; 
 $ sql。=“WHERE sp_id =”。$ id。“AND show = 1”; 
 $ sql。=“ORDER BY shop_id asc”; 
 $ query = $ this-&gt; db  - &gt; query($ sql); 
   
 
 

返回$ query-&gt; row;

并部分使用ajax:

 &lt; div id =“content”class =“group”&gt; 
&lt; div id =“backItem”&gt; 
&lt; div id =“footerItemContent  “&gt; 
&lt; / div&gt; 
&lt; div id =”footerItemDivider“&gt;  - &lt; / div&gt; 
&lt; div id =”footerItemCustomer“&gt; ...&lt; / div&gt; 
  &lt; / div&gt; 
&lt; / div&gt; 
&lt; / div&gt; 
&lt; / div&gt; 
   
 
 

和我的功能 \ n

  $(document).ready(function(){
var products = function(){
 
 for(var i = 0; i&lt; complex.length; i ++){\  n 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&lt;  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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题