douan3182 2014-10-06 16:45
浏览 58

如何用fadein逐个循环从mysql加载数据?

How to load data from mysql with fadein one by one loop ?

OK, i will load image from mysql total 40 image

Then i want to display

<li class="img" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
    <img src="<?PHP echo $img_products[0]; ?>"/>
</li>

with fadein and delay 0.5 sec. And then display

<li class="img" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
    <img src="<?PHP echo $img_products[1]; ?>"/>
</li>

with fadein and delay 0.5 sec. And then display

<li class="img" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
    <img src="<?PHP echo $img_products[2]; ?>"/>
</li>

with fadein and delay 0.5 sec. And then display

<li class="img" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
    <img src="<?PHP echo $img_products[3]; ?>"/>
</li>

until display to

<li class="img" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
    <img src="<?PHP echo $img_products[39]; ?>"/>
</li>

i try to using loop for PHP to do that , but not work, How an i do that ?

<?PHP 
for($i=0;$i<40;$i++)
{
    $strSQL = "SELECT * FROM products WHERE data_type = '$strID' order by id desc Limit $i,1 ";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    $objResult = mysql_fetch_array($objQuery);
    $img_products[$i] = $objResult["img_path"];
}


for($i=0;$i<40;$i++)
{
<li class="img" style=" list-style: none; float: left; margin: 7px; width: 80px; ">
    <img src="<?PHP echo $img_products[$i]; ?>"/>
</li>
}
?>
  • 写回答

1条回答 默认 最新

  • douwen3362 2014-10-07 15:56
    关注

    Ok, you need to 1st output the html for all 40 images in php. Making 40 queries is just illogical, so i have changed that to make 1 query with a limit of 40 results.

    <?php
    $strSQL = "SELECT * FROM products WHERE data_type = '$strID' order by id desc Limit 40";
    $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
    while($row = mysql_fetch_array($objQuery)):?>
    
        <li class="img" style="display:none; list-style: none; float: left; margin: 7px; width: 80px; ">
            <img src="<?php echo $row["img_path"]; ?>"/>
        </li>
    
    <?php endwhile;?>
    

    Also note that the <li> tags are hidden with css using display:none;. Then using javascript (in this case with jquery) you can loop through all the li tags, and set a timer to show them. The loop works by increasing the timout by 500 miliseconds per item:

    <script src='http://code.jquery.com/jquery-1.11.0.min.js'></script>
    <script>
    $(function(){
        $('li.img').each(function(index){
            $(this).delay(500*index).fadeIn(400);
        });
    });
    </script>
    

    Obligatory note: mysql_* functions are depreciated. You should instead use mysqli_* or pdo instead

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)