PHP/MySQL 2 'while' 语句来自 1 个 mysql 查询? [英] PHP/MySQL 2 'while' statements from 1 mysql query?

查看:45
本文介绍了PHP/MySQL 2 'while' 语句来自 1 个 mysql 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用相同的 'mysql_query' 有 2 个 'while' 语句?

我正在使用 jquery 拇指图库,其中的结果是从数据库中提取的.图库要求图像在无序列表中组合在一起,文本/覆盖内容在隐藏的 div 中组合在一起,这些 div 需要与无序列表分开.这样做的原因是因为有许多潜在的结果可以进入这里并且随机引入它们似乎是有意义的.

这是我目前使用的代码:非常感谢任何帮助,S.

';}?>

解决方案

尝试通过在两次 while 循环之间调用 mysql_data_seek($homeB, 0) 来重置查询结果的迭代器.>

I was wondering if it's possible to have 2 'while' statements using the same 'mysql_query'?

I'm using a jquery thumb gallery with the results pulled in from a database. The gallery requires that the images are grouped together in an unordered list, with the text/overlayed content grouped together in hidden divs which need to be separate from the unordered list. The reason for doing this is because there are many potential results that could go in here and bringing them in randomly seems to make sense.

Here's the code I'm currently using: Any help greatly appreciated, S.

<div id="banner-wrap">          
        <div id="banner" class="gallery">               
            <ul class="galleryBar">               

                    <?php       
                    $homeB=mysql_query("select * from istable where fpGallery = '1' ORDER BY RAND() LIMIT 0, 5");
                    while($homeG=mysql_fetch_array($homeB)) {   
                    $linkcode = $homeG['title'];
                    $linkcode = str_replace(" ","",$linkcode);
                    echo '
                    <li>
                    <a href="'.$wwwUrl.'images/'.$homeG['image'].'" rel="'.$linkcode.'">
                    <img src="'.$wwwUrl.'images/tn/'.$homeG['image'].'" width="75" height="55" alt="'.$homeG['title'].'" />
                    </a>
                    </li>                       
                    ';
                    }                                   

            echo '</ul>';
             echo '</div>'; 

                    while($homeGal=mysql_fetch_array($homeB)) {                             
                    echo '
                    <div id="'.$linkcode.'" class="overlay">
                        <h3>'.$homeGal['title'].'</h3>
                        <h4>'.$homeGal['location'].'</h4>                           
                    </div>                                              
                    ';
                    }

                    ?>          
        </div>

解决方案

Try to reset the iterator of the query result by calling mysql_data_seek($homeB, 0) between the two while loops.

这篇关于PHP/MySQL 2 'while' 语句来自 1 个 mysql 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆