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

  • SEARCH
  • Home
  • 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 8437085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:20:24+00:00 2026-06-10T07:20:24+00:00

I have an html select box that is populated by an array from the

  • 0

I have an html select box that is populated by an array from the db. All the data in this table including the select box it written to a new table in the db along with current date. When the user returns to the class I want the select box to default to the last entry the user submitted whether it be the day before or a week before. I can get the query pretty close to where I need it but I dont really where to start as far as passing that to the select box.

Here is my select box that is echo from php.

    <td>
              <select name="movement[]" width=200>
              <option>Select...</option>
              <option>'. ($wc['mv_00']). '</option>
              <option>'. ($wc['mv_01']). '</option>
              <option>'. ($wc['mv_02']). '</option>
              <option>'. ($wc['mv_03']). '</option>
              <option>'. ($wc['mv_04']). '</option>
        </select></td>

Here is the code for the entire array that is echo out.

    if(empty($workout_class) === false)
{   
foreach($workout_class as $wc){
if ($wc['pagenum'] !== $pagenum) continue 1;

    echo '<tr>
        <td><input type="hidden" name="client_id[]" value="'.($wc['client_id']).'">
        <input type="hidden" name="first_name[]" value="'.($wc['first_name']).'">'. ($wc['first_name']).'
        <span><input type="hidden" name="nickname[]" value="'.($wc['nickname']).'">('. ($wc['nickname']).')</span>
        <span><input type="hidden" name="last_name[]" value="'.($wc['last_name']).'">'. ($wc['last_name']).'</span>
        </td>
              <td><input type="hidden" name="order[]" value="'.($wc['order']).'">'. ($wc['order']). '</td>
              <td>
              <select name="movement[]" width=200>
              <option>Select...</option>
              <option>'. ($wc['mv_00']). '</option>
              <option>'. ($wc['mv_01']). '</option>
              <option>'. ($wc['mv_02']). '</option>
              <option>'. ($wc['mv_03']). '</option>
              <option>'. ($wc['mv_04']). '</option>
        </select></td>
        <td><input type="hidden" name="rep_set_sec[]" value="'.($wc['rep_set_sec']).'">'. ($wc['rep_set_sec']). '</td>
        <td><input type="hidden" name="rest[]" value="'.($wc['rest']).'">'. ($wc['rest']). '</td>
        <td>00</td>
        </tr>';    
   } // foreach($data_array

Can this be done with php or is this something where js would be better?

OK, here is my variable that get the last movement entered based on the class, client and order.

    $recent_movement = recent_movement($class_id, $client_id, $order);

Here is my query that returns the array of movements from db based on MAX(date)

function recent_movement($class_id, $client_id, $order){
    $class_id = (int)$class_id;
    $client_id = (int)$client_id;

$query = mysql_query("SELECT `movement` FROM `completed_movements` WHERE `class_id` = '$class_id' AND `client_id` = '$client_id' AND `order` = '$order' AND
`date` = (SELECT MAX(`date`) FROM `completed_movements` WHERE `order` = '$order')");

$last_movement = mysql_fetch_array($query);

return $last_movement['movement'];

}

This is where Im not sure how to tell the select menu to set select=”selected” based on what my $recent_movement returns.

  • 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-10T07:20:25+00:00Added an answer on June 10, 2026 at 7:20 am

    OK, for argument’s sake, let’s say that you store the latest selection in $recent_movement. Just compare the value of that variable to the value of the options, and set the matching option to “selected”:

    <?php
    .
    .
    .
    echo '...
    
        <option' . ($ws['mv_00'] == $recent_movement ? ' selected="selected"' : "") . '>'. ($wc['mv_00']). '</option>
        <option' . ($ws['mv_01'] == $recent_movement ? ' selected="selected"' : "") . '>'. ($wc['mv_01']). '</option>
        <option' . ($ws['mv_02'] == $recent_movement ? ' selected="selected"' : "") . '>'. ($wc['mv_02']). '</option>
        <option' . ($ws['mv_03'] == $recent_movement ? ' selected="selected"' : "") . '>'. ($wc['mv_03']). '</option>
        <option' . ($ws['mv_04'] == $recent_movement ? ' selected="selected"' : "") . '>'. ($wc['mv_04']). '</option>
    
    ...';
    

    You can also simplify this by implementing a loop with a counter:

    <?php
    
    $options = "";
    for($i = 0; $i <= 4; $i++) {
        $options .= '<option' . ($ws['mv_0' . $i] == $recent_movement ? ' selected="selected"' : "") . '>'. ($wc['mv_0' . $i]). '</option>';
    }
    

    UPDATE:

    Had this been my own code, I would have made some minor changes. Instead of that huge echo, I would have just exited PHP mode and gone with straight HTML. I would have also used my looping string constructor (posted above) for the options:

    <?php
    foreach ($workout_class as $wc) :
        if ($wc['pagenum'] !== $pagenum) continue 1;
    
        $options = "";
    
        for ($i = 0; $i <= 4; $i++) {
            $options .= '<option' . ($ws['mv_0' . $i] == $recent_movement ? ' selected="selected"' : "") . '>' . ($wc['mv_0' . $i]) . '</option>';
        }
        ?>
        <tr>
            <td><input type="hidden" name="client_id[]" value="<?= $wc['client_id'] ?>">
                <input type="hidden" name="first_name[]" value="<?= $wc['first_name'] ?>"><?= $wc['first_name'] ?>
                <span><input type="hidden" name="nickname[]" value="<?= $wc['nickname'] ?>">(<?= $wc['nickname'] ?>)</span>
                <span><input type="hidden" name="last_name[]" value="<?= $wc['last_name'] ?>"><?= $wc['last_name'] ?></span>
            </td>
            <td><input type="hidden" name="order[]" value="<?= $wc['order'] ?>"><?= $wc['order'] ?></td>
            <td>
                <select name="movement[]" width=200>
                    <option>Select...</option>
                    <?= $options ?>
                </select></td>
            <td><input type="hidden" name="rep_set_sec[]" value="<?= $wc['rep_set_sec'] ?>"><?= $wc['rep_set_sec'] ?></td>
            <td><input type="hidden" name="rest[]" value="<?= $wc['rest'] ?>"><?= $wc['rest'] ?></td>
            <td>00</td>
        </tr>
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have a PHP/HTML select box that is created dynamically from
I have a classic HTML select box: Show: <select name=show id=showThreads> <option value=all selected=selected>All</option>
I have a html element (like select box input field) in a table. Now
I have a html form which have a select list box from which you
I have a form in a .html files where input/select box looks like this
I have a javascript function. This function is supposed to populate a html select-box
I have 3 select boxes, all populated with the same data. Using jquery I
I have a select box that gets populated through a Backbone Collection: class Prog.Views.History
I have a select html element that is populated with jquery inside an ajax
I have a listbox (multi-select) in my web form that is populated from a

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.