1

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>

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0
WHERE `column1` = 'value1' AND `column2` = 'value2'

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.