Jump to content

PHP For Loop


guestabc

Recommended Posts

Hi I need a bit of help with a for loop nested within another for loop.

SQL Query of Questions
     For Loop
     {
          Output Data
          SQL Query Of Possible Answers
          [i]Output answer image here[/i]
               For Loop
               {
                    Output Data
               }
       }

 

The above is simple and I have the data displaying as I want it however I now want to output an image that relates to the second SQL query (answers), but I only need one image to output per question. The problem comes that I am accessing the mysql_fetch_array inside the second for loop meaning that I have to output the image inside this loop, but this means all images will be output? I hope it is clear to you what I am trying to do here and thanks for any help in advance!

 

Link to comment
Share on other sites

  //SQL Query of Questions
$image_displayed=0;
     //For Loop
     {
       //   Output Data
        //  SQL Query Of Possible Answers
if($image_displayed==0){
          [i]Output answer image here[/i]
$image_display++;
}
               For Loop
               {
                    Output Data
               }
       }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.