tags:

views:

45

answers:

3

Hi,

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>
A: 
WHERE `column1` = 'value1' AND `column2` = 'value2'
Alexander.Plutov
That's not at all what he needs..
joni
+1  A: 

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

Flinsch
A: 

Your unindented code is hard to follow but it appears that you're asking whether mysql_fetch_array() starts again when it reaches the last row. The answer to that is no.

Can you rewind the result set? In theory, you can (find mysql_data_seek() in the manual). But there's no need to make it so complicate: just read data once, store it into an array and loop the array as many times as you need.

Álvaro G. Vicario