Jump to content

Retrieve value stored in ENUM for default option in drop down menu


mfaulkner

Recommended Posts

Hi all,

 

This problem has had be going round in circles now for a couple of weeks, if somebody could provide a solution I would be really really grateful.

 

First off, what I want to do...

 

Have an HTML drop down menu that can set a status of a day to 'Available' or 'Booked'. Inserting the initial data isn't important, so its only function is as an update form/query.

 

Its a really simple MySQL database, with only 1 table and 2 fields. (The day field is the primary key).

 

So, when the page is loaded, the default option should be selected in the drop down menu, then it can be modified if necessary.

 

As its an update form its imperative that the stored value in the ENUM (Available or Booked) is selected as the default.

 

Once I have it working for 1 day, I should be able to modify it for a complete month, then year.

 

 

 

 

Thanks in advance guys.

 

Mark.

 

 

 

Here's what I've attempted (unsuccessfully) so far plus a couple of screenshots to make clear the database structure.

 

<?php
	$jan = "SELECT jan_day, jan_status FROM january WHERE jan_day = 1";
	$result = mysql_query($jan) 
		or die ("Error in query: $query. " . mysql_error());
	while (list($jan_day, $jan_status) = mysql_fetch_row($result)) {
?>
<form>
<select name="jan_1" size="1">
<option value="1" <?php 
					if ($result['jan_status'] == "1")
					{
						echo "selected";
					}
				?>>Available</option>

<option value="2" <?php 
					if ($result['jan_status'] == "2") 
					{
						echo "selected";
					}
				?>>Booked</option> <?php } ?>
</select>
</form>

 

Picture%201.png

 

Picture%202.png

Link to comment
Share on other sites

What am I missing?  If jan_status can have two values - available and booked - why are you using 1 and 2 as the options in a select dropdown for jan_status. Surely, your dropdown values need to be available and booked, not 1 and 2?

Link to comment
Share on other sites

What am I missing?  If jan_status can have two values - available and booked - why are you using 1 and 2 as the options in a select dropdown for jan_status. Surely, your dropdown values need to be available and booked, not 1 and 2?

 

Having just read the post three times, I totally agree.

 

Mfaulkner, I think your logic has gone awry somewhere along the line.

 

Regards

Huggie

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.