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
https://forums.phpfreaks.com/topic/213233-php-for-loop/
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
https://forums.phpfreaks.com/topic/213233-php-for-loop/#findComment-1110308
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.