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 8092153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:13:36+00:00 2026-06-05T20:13:36+00:00

Using PHP I echo out table rows in a loop like this: <?php /*

  • 0

Using PHP I echo out table rows in a loop like this:

<?php
/* SQL STUFF */

  while ($row = mysql_fetch_array($select_courseelements)) {
   echo "<tr>\n";
    echo "<td>".$row['scpe_name']."</td>\n";
    echo "<td>".$row['scpe_days']."</td>\n";
   echo "</tr>\n";
  }

Now I would like to include a <select> element with 5 predefined <option> values inside a <td> running with the loop. The option values will be 1 to 5.

There is also a column inside the $row loop that holds a value of 1 to 5 ($row['scpe_grades_status']).

Each time this value is equal to the one in the <select> I want it to change it to selected='selected'.

Would this be possible?

My <select> will look something like this when it’s being run in the loop:

echo "<td>\n";
echo "<select id='elements_grade'>\n";
        echo "<option value='1'>Registrerad</option>\n";
        echo "<option value='2'>Ej påbörjad</option>\n";
        echo "<option value='3'>Pågående</option>\n";
        echo "<option value='4'>Godkänd</option>\n";
        echo "<option value='5'>Deltagit</option>\n";
        echo "<option value='6'>Ej deltagit</option>\n";
echo "</select>\n";
echo "</td>\n";
  • 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-06-05T20:13:37+00:00Added an answer on June 5, 2026 at 8:13 pm
    $array = array('Registrerad' => 1, 'Ej påbörjad' => 2, 'Pågående' => 3, 'Godkänd' => 4, 'Deltagit' => 5, 'Ej deltagit' => 6);
    
    foreach ($array as $key=>$value) {
        if ($value == $row['scpe_grades_status'])
            echo '<option value="'.$value.'" selected>'.$key.'</option>';
        else
            echo '<option value="'.$value.'">'.$key.'</option>';
    }
    

    Something like that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using php to do this: while ($row = mysql_fetch_object($db_list)) { echo $row->Database .
in Php, I want to print Düsseldorf using echo 'Düsseldorf'; However it turns out
I'm using CodeIgniter (because it's awesome) and I have something like: <?php echo anchor(/,
I am exporting a SQL Server table to a CSV using php (see code
I have a table like this in mysql called links_tbl which has 5 rows
I'm using this php code to update a table, but nothing is updating? if(isset($Submit))
I'm using PHP to echo a content stored on my database. The content is
I am using Twitter Bootstrap to style validation_errors for a registration page: <?php echo
Using PHP, I can convert MySQL data or static table data to csv, Excel,
using php and mysql I have two tables, a users table and a profiles

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.