TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Another quetion - Loop inside a loop (http://www.talkphp.com/general/2865-another-quetion-loop-inside-loop.html)

Jmz 05-30-2008 08:00 PM

Another quetion - Loop inside a loop
 
I'm lost trying to work out where I'm going wrong here. I think I've been staring at the code so long I can see what I'm doing *!*

Basically the first loop gets the images from the database and the second one populates an option form field with the names and values of the galleries from the database.

I've sort of got it working but on the for the first record, then the option menus dont display properly.

Also, I'm sure there's a better, more efficient way to do the whole thing.

Here's my code:

PHP Code:

<?php
    
include("templates/header.php");
    include(
"../config/connect.php");
    
    
$SiteURL "http://play.jamesowers.co.uk/photo/";
    
    
$images_query "SELECT * FROM tbl_images WHERE fld_userid = '1' AND fld_galid = '0'"
    
$gallery_query "SELECT fld_galleryname, fld_id from tbl_gallery WHERE fld_userid = '1'";
    
$result mysql_query($images_query);
    
$result2 mysql_query($gallery_query);
    while (
$row mysql_fetch_assoc($result)){
    
    
$imageurl $row['fld_imgurl'];
    echo 
"<div class=\"mod_gal_top\"><img src=\"images/cross.png\" /></div>\n";
    echo 
"<div class=\"mod_gal_mid\">";
    echo 
"<div class=\"mod_gal_img_box\">";
    echo 
"<img src=\"".$SiteURL."usercp/uploads/".$imageurl."\" class=\"mod_gal_img\"/>";
    echo 
"</div>";
    echo 
"<form action=\"action/modify_photo.php\" method=\"post\" class=\"galimg_form\">\n";
    echo 
"<label for=\"imgname\">Image Name</label><input type=\"text\" name=\"imgname\"/><br />\n";
    echo 
"<label for=\"imggal\">Image Gallery</label>\n";
    echo 
"<select name=\"imggal\"/>\n";
        while (
$row2 mysql_fetch_assoc($result2)){
            
$galid $row2['fld_id'];
            
$galname $row2['fld_galleryname'];
            echo 
"<option value=\"$galid\">$galname</option>\n";
        }
    echo 
"</select>\n";
    echo 
"<label for=\"imgdesc\">Image Description</label><input type=\"text\" name=\"imgdesc\"/><br />\n";
    echo 
"</form>";
    echo 
"<br class=\"clear\"/></div>\n";
    }
?>



<?php include("templates/nav.php"); ?>
<?php 
include("templates/footer.php"); ?>


Jmz 05-30-2008 09:07 PM

I managed to get this fixed finally :-D

I needed to add:
Code:

// seek back to record #1 for the next loop
            mysql_data_seek($result2, 0);
            $row2 = "";

To reset the inner loop.


All times are GMT. The time now is 08:23 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0