TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-30-2008, 08:00 PM   #1 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default 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"); ?>
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Old 05-30-2008, 09:07 PM   #2 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default

I managed to get this fixed finally

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.
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:52 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design