Jump to content

Check Boxes From drop-downlist


SalientAnimal
Go to solution Solved by SalientAnimal,

Recommended Posts

Hi All,

 

I want to create a form that will have a drop-down list where you would select various timeslots.

 

The drop-down will have options such as:

08:00 - 17:00

09:00 - 18:00

10:00 - 19:00

11:00 - 20:00

12:00 - 21:00

etc.

 

When selecting either one of these options in the drop-down I need my database to be queried and to return a list of names (Users scheduled to work). Next to each name I would like it to have a check box, which the person accessing the form can then tick indicating if a user is present / absent.

 

For all present users, their names need to be written to a new table, separated by only a comma, e.g. user1, user2, user3, etc.

On the same row of the table, but in a new column the same has to apply or users who are absent

And a third column for users who are late.

 

So my quests are as follows:

1. Can this be done?

2. How do I retrieve the correct info from the table based on the drop down

3. What is the best way to name my check boxes? Would it be (Present1, Absent1, Late1, Present2, Absent2, Late2, etc)?

 

I haven't started building the page as yet, but do have a table where a schedule is loaded with the shifts as indicated.

 

Any suggestions will be most welcome.

 

Link to comment
Share on other sites

For all present users, their names need to be written to a new table, separated by only a comma, e.g. user1, user2, user3, etc.

On the same row of the table, but in a new column the same has to apply or users who are absent

And a third column for users who are late.

 

Um, no. That is a NOT how you should be storing the records. Based upon this and your other post I see that you really, really need to do some research on database normalization. The things you are trying to do are only going to make your life harder.

 

 

 

1. Can this be done?

Yes. But, it should be done differently than you think it should.

 

2. How do I retrieve the correct info from the table based on the drop down

No idea. Your explanation above makes no sense. You select a time period and retrieve a list of users based on what? You then select checkmarks next to the users' names that does what? You then want to store records associated for the user based on whether they are present, absent or late. How is this determined, the checkbox? A checkbox only has two possible states: checked or not checked. So, how do you determine the three statuses?
 
 

3. What is the best way to name my check boxes? Would it be (Present1, Absent1, Late1, Present2, Absent2, Late2, etc)?

Ok, from this it appears you are now wanting three checkboxes per user even though you clearly stated previously you would only have one. Why checkboxes? They are not mutually exclusive and makes your life harder. I.e. a user could check the Present AND the Absent checkboxes for the same user. So you would have to add additional validation logic. Just provide a single select list with the three options for each user. And the fields should be something like this:

 

<select name="present[34]">
<option value="0">Absent</option>
<option value="1">Present</option>
<option value="2">Late</option>
</select>

The 34 in the name would represent the user ID of the user that the field is associated with. You POST data would then contain an array with the values for all the user.

Link to comment
Share on other sites

I was thinking checkboxes / radio buttons because there would be multiple users working the same shifts. Was also thinking that having a dropdown menu next to each used might look cluttered, and it makes it a little teadious when you have a list of 20+ users and you have to select a drop-down option for each.

 

 

I actually later realised that he best way would be to rather create a new entry for each user, but this would mean that there would be multiple submits when hitting the submit button?

Edited by SalientAnimal
Link to comment
Share on other sites

  • Solution

Ok, so I've done some work on this and tried applying the logic you had helped me with in an earlier thread. I'm almost certain that I'm not doing this right though.

<?php
 
//FUNCTION TO CREATE HTML FOR OPTIONS LIST
function createOptions($optionList, $selectedValue)
{
    $options = '';
    foreach ($optionList as $option)
    {
        $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : '';
        $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n";
    }
    return $options;
}
 
//DETERMINE SELECTED OPTIONS PASSED ON QUERY STRING
$shift   = isset($_GET['shift'])   ? intval($_GET['shift'])   : false;
$agent = isset($_GET['agent']) ? intval($_GET['agent']) : false;
//$tertiary_category  = isset($_GET['tertiary_category'])  ? intval($_GET['tertiary_category'])  : false;
 
 
 
 
//GENERATE OPTIONS FOR THE SHIFT OPTIONS
$query = "SELECT DISTINCT id AS value, shift AS label
          FROM shift_structure
		  WHERE active_status = 1
          ORDER BY id"; 
$optionList = $dbo->query($query);
$shift_options = createOptions($optionList, $shift);
 



//SELECTING THE AGENTS THAT ARE SCHEDULE FOR THE MENTIONED SHIFT 
if($shift)
{
    $query = "SELECT shift AS value, agent AS label
              FROM schedule
              WHERE id = $shift
              ORDER BY agent";
    $optionList = $dbo->query($query);
    $agent_options = createOptions($optionList, $agent);
}





 
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Shift Report - Agent Analysis</title>
    <script language="javascript">
 
        function getSelectValue(selectID)
        {
            var optionObj = document.getElementById(selectID);
            return optionObj.options[optionObj.selectedIndex].value;
        }
 
        function reload(form)
        {
            //Adding the unselected options should work fine
            var locationURL = 'shift_form_schedule.php';
                locationURL += '?shift='   + getSelectValue('shift');
         //       locationURL += '&secondary_category=' + getSelectValue('secondary_category');
        //        locationURL += '&tertiary_category='  + getSelectValue('tertiary_category');
            //Perform the reload
            self.location = locationURL;
        }
 </script>


<!-- INCLUDING THE NAVIGATION MENU -->


<?php
// INCLUDING THE TOP LOGIN / LOGOUT PANEL
include 'includes/panel.php';

// INCLUDING THE NAVIGATION MENU
include '/nav/menu.html';
 
?>






    <div id="container">
		<div id="content" style="margin-top:-45px;">
		<img src="images/logo.png" alt="Altech Autopage"></img>
			<h1>Auxilium</h1>
			<!-- <h2>Sliding login panel with jQuery - Demo</h2>	 -->
		
		<div id="stylized" class="form">
			<form id="form" name="form" method="post" action="process/submit_voc.php">
			<h1>VOC Root Cause Analysis</h1>
			<!--<p>This is the basic form layout. We can edit it as required.</p>-->

			<!-- DISPLAY THE DETAILS OF THE LOGGED IN USER -->
			<label>User Logged In :
			<span class="small">You are logged in as</span>
			</label>
			<input type="text" name="username" id="username" value="<?php echo htmlentities($_SESSION['username']);?>" readonly style="background-color: #C9C9C9">
			
			
			<!-- DISPLAY THE DETAILS OF THE LOGGED IN USER 
			<label>Form Reference Number :
			<span class="small">Number Reference to link queries</span>
			</label>-->
			<input type="hidden" name="voc_reference" id="voc_reference" value="<?php echo $random;?>" readonly style="background-color: #C9C9C9">			
			
			<label>Shift :
			<span class="small">Shift that is being updated</span>
			</label>
    		<select name='shift' id='shift' onChange="reload(this.form)">
       		<option value=''>--- Select a Shift ---</option>
        	<?php echo $shift_options; ?>
    		</select>
	


			<label><?php print $agent;?> :
			<span class="small">Agent being updated</span>
			</label>
			<input type ='radio' name='present' value="<?php echo $agent;?>">
			<?php print $agent;?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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