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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:51:28+00:00 2026-06-07T00:51:28+00:00

All, If I’ve go the following database fields/values: user_id field_name field_value 1 EventHour1 1

  • 0

All,
If I’ve go the following database fields/values:

user_id     field_name     field_value
1           EventHour1     1
1           EventMinute1   30
1           EventAMPM1     am
1           Event_1        Set Up
1           EventHour2     5
1           EventMinute2   30
1           EventAMPM2     am
1           Event_2        Take Down

Then I have the following HTML/PHP:

<?php
for($i=0;$i<50;$i++){
if ($i%2==0){
    echo '<tr bgcolor="#CCCCCC">';
} else {
echo '<tr>';
}
?>
<td><select size="1" id="EventHour<?php echo $i; ?>" name="EventHour<?php echo $i; ?>" > 
    <option>1</option> 
    <option>2</option> 
    <option>3</option> 
    <option>4</option> 
    <option>5</option> 
    <option>6</option> 
    <option>7</option> 
    <option>8</option> 
    <option>9</option> 
    <option>10</option> 
    <option>11</option> 
    <option>12</option> 
  </select> : <select size="1" name="EventMinute<?php echo $i; ?>" id="EventMinute<?php echo $i; ?>" > 
    <option>00</option> 
    <option>05</option> 
    <option>10</option> 
    <option>15</option> 
    <option>20</option> 
    <option>25</option> 
    <option>30</option> 
    <option>35</option> 
    <option>40</option> 
    <option>45</option> 
    <option>50</option> 
    <option>55</option> 
  </select> 
  <select size="1" name="EventAMPM<?php echo $i; ?>" id="EventAMPM<?php echo $i; ?>"> 
    <option>PM</option> 
    <option>AM</option> 
  </select></td> 
<td><b>&nbsp; 
  <select size="1" name="Event_<?php echo $i; ?>" id="Event_<?php echo $i; ?>" class="event_selection"> 
    <option>Select Event...</option> 
    <option value="Set Up">Set Up</option> 
    <option value="Take Down">Take Down</option> 

  </select> 
  </b></td> 
<td>&nbsp;Note:
  <input type="text" name="Note<?php echo $i; ?>" id="Note<?php echo $i; ?>"> 
  </td> 
</tr> 
<?php
}
?>

What I’d like to do is set the select values based on the database results. So if the select id is EventHour1 then I’d like to make the select option be 1 and if it was Event_2 then I’d like the select option to be Take Down.

How can I go about doing this with PHP? Any help would be greatly appreciated!

Thanks in advance

  • 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-07T00:51:30+00:00Added an answer on June 7, 2026 at 12:51 am

    Here’s the basic idea using an array. Ideally the options would be read from a database instead (the \t and \n are just to keep the output HTML format clean when you have to view source to debug – you can also use <?php echo $i?> method to output if you prefer):

    $curVal = /* lookup curVal from database for event */
    echo "<select size='1' id='EventHour$i' name='EventHour$i'>\n";
    $options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
    foreach ($options as $option) {
        if ($curVal == $option)
            $selected = " selected='selected'";
        else
            $selected = "";
        echo "\t<option$selected>$option</option>\n";
    }
    echo "</select>\n\n";
    

    Which should render something like this for Event 2, for example:

    <select size='1' id='EventHour2' name='EventHour2'>
        <option>1</option> 
        <option>2</option> 
        <option>3</option> 
        <option>4</option> 
        <option selected='selected'>5</option> 
        <option>6</option> 
        <option>7</option> 
        <option>8</option> 
        <option>9</option> 
        <option>10</option> 
        <option>11</option> 
        <option>12</option>
    </select>
    

    Demo: http://ideone.com/BoEfr


    I also question your database design. If you are trying to store events in the database, I think you are confusing the presentation concerns (field id’s etc), with data storage. Your database just needs to capture the underlying data semantics, which are the details of the events:

    event_id | user_id | event_name | hour | minute | am_pm
    1        | 1       | Set Up     | 1    | 30     | am
    2        | 1       | Take Down  | 5    | 30     | am
    

    Then when you are displaying the events, you take care of presenting it in a meaningful manner, i.e., in a table format with dropdowns or textboxes for data entry.

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

Sidebar

Related Questions

All, Say I have the following bit of code: select: function(start, end, allDay) {
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I have the following code: $fetch = mysql_query(SELECT * FROM calendar_events where event_status='booked'
All, I have the following class so to check to see if the form
All, If I run a query like the following: $qry = Select wrong_column from
all i want to create the header file for database like this. it contains
All I have the following form input element: <input name=payment_amount type=text id=payment_amount value= disabled>
All, I have the following hidden field on my page: <input type=hidden name=timeline_num[] id=timeline_num
All, I have the following select box: <select class=event_selection name=Event[] id=Event_<?php echo $i; ?>
All, I've got the following jQuery code: jQuery.post(site_url + save_data.php, jQuery(this).serialize(), function(data) { //alert(Data

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.