Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7062887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:38:53+00:00 2026-05-28T04:38:53+00:00

I have a while and foreach loop that I want to use to print

  • 0

I have a while and foreach loop that I want to use to print all of my results from a MySQL query. Below is my code for the while statement and the foreach statements.

WHILE:

while ($row_questions = mysql_fetch_array($result_questions)) {

 $step_number[]      = $row_questions['step_number'];

 if ($row_questions['step_number_sub'] != 0) {
   $step_number_sub[]  = $row_questions['step_number_sub'];
 } else {
   $step_number_sub[]  = "0";
 };

 if ($row_questions['step_required'] != 0) {
   $step_required[]  = "*";
 } else {
   $step_required[]  = "";
 };

 $step_description[] = $row_questions['step_description'];
 $step_outcome[]     = $row_questions['step_outcome'];
 $step_equipment[]   = $row_questions['step_equipment'];
 $test_changes[]     = $row_questions['test_changes'];
};

and my FOREACH:

foreach ($step_number as $i => $step){
    $even_odd = ( '-odd' != $even_odd ) ? '-odd' : '';
    echo '<section class="zebra'.$even_odd.'">';
    echo '<div class="span-2 number"><strong>'.$step_number[$i].'</strong></div>';
    echo '<div class="span-20 description">'.$step_description[$i].'</div>';
    echo '<div class="span-2">'.$step_required[$i].'</div>';
    if ($step_outcome[$i] != null) {
      echo '<div class="span-22 outcome"><strong>Desired Outcome</strong><br>'.$step_outcome[$i].'</div>';
    }
    echo '<div class="clear"></div>';
    echo '<article class="results">';
    echo '<div class="span-10">Did this step match the desired outcome?</div>';
    echo '<div class="span-10">Notes:</div>';
    echo '<div class="span-10">
          <select name="question_'.$step[$i].'" id="question_'.$step[$i].'" required aria-required="true">
          <option name="pass" value="Pass">Yes, this step was completed successfully</option>
          <option name="fail" value="Fail">No, this step failed to complete. See notes below</option>
          </select>
          </div>';
    echo '<div class="span-10"><textarea name="question_'.$step[$i].'" id="question_'.$step[$i].'" class="nots"></textarea></div>';
    echo '</article>';
    echo '<div class="clear"></div>';
    echo '</section>';
};

I am getting multiple versions of the same results (4). Thanks in advance for any help and let me know if you need any other info!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:38:54+00:00Added an answer on May 28, 2026 at 4:38 am

    Don’t use multiple arrays. Use a class structure or array for each element. A simple way to do this:

    while ($row_questions = mysql_fetch_array($result_questions))
        questions[] = $row_questions;
    
    foreach( $questions as $question )
    {
        $even_odd = ( '-odd' != $even_odd ) ? '-odd' : '';
        echo '<section class="zebra'.$even_odd.'">';
        echo '<div class="span-2 number"><strong>'.$question['step_number'].'</strong></div>';
        echo '<div class="span-20 description">'.$question['step_description'].'</div>';
        echo '<div class="span-2">'.$question['step_required'].'</div>';
        if ($question['step_outcome'] != null) 
        {
          echo '<div class="span-22 outcome"><strong>Desired Outcome</strong><br>'.$question['step_outcome'].'</div>';
        }
       ... you get the drift ...
      };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL database and I use a while loop to take information
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
The while loop I have while reading in from a file doesn't break. I'm
I have a case where I want to use the results of a prepared
What I want to do is have a while statement which loops whilst the
I have read that while plug-ins are not supported for SQL Server Management Studio,
I have two simple while loops in my program that I feel ought to
I have a dataset that I read in from a complex xml structure.... here
I have a stored procedure below. In it is a nested loop. Instead of
I have a class that inherits from Dictionary<string, string> . Within an instance method,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.