hi,
i'm using menu for displaying birth month of user...
i hav added 12 entries denoting 12 months of a year.
items and thier values are...
Item Value
Jan 1
Feb 2
... .
... .
Nov 11
Dec 12

the values are stored in Database.

Problem is viewing the deatails in editing page.
Instead showing 12 items, it shows 13 items (12 items in menu+itemselected)

say, Mar... it shows march twice & other items once...

Help to solve my problem...

Recommended Answers

All 6 Replies

<label>
                    <select name="month" id="month">
                    <OPTION SELECTED>
	      <?php echo $this_month;?>
	      <option value="1">Jan</option>
                      <option value="2">Feb</option>
                      <option value="3">Mar</option>
                      <option value="4">Apr</option>
                      <option value="5">May</option>
                      <option value="6">Jun</option>
                      <option value="7">Jul</option>
                      <option value="8">Aug</option>
                      <option value="9">Sep</option>
                      <option value="10">Oct</option>
                      <option value="11">Nov</option>
                      <option value="12">Dec</option>
                    </select>
                  </label>

The echo is the 13th option. Try this:

<select name="month" id="month">
	<option value="1" <?php echo if ($this_month == 'Jan') echo 'selected'; ?>>Jan</option>
	<option value="2" <?php echo if ($this_month == 'Feb') echo 'selected'; ?>>Feb</option>
	<option value="3" <?php echo if ($this_month == 'Mar') echo 'selected'; ?>>Mar</option>
	<option value="4" <?php echo if ($this_month == 'Apr') echo 'selected'; ?>>Apr</option>
	// etc.
</select>

A better way would be to use a loop.

<select name="month" id="month">
    <option value="1" <?php echo if ($this_month == 'Jan') echo 'selected'; ?>>Jan</option>	
    <option value="2" <?php echo if ($this_month == 'Feb') echo 'selected'; ?>>Feb</option>	
    <option value="3" <?php echo if ($this_month == 'Mar') echo 'selected'; ?>>Mar</option>	
    <option value="4" <?php echo if ($this_month == 'Apr') echo 'selected'; ?>>Apr</option>
    <option value="5" <?php echo if ($this_month == 'May') echo 'selected'; ?>>May</option>	
    <option value="6" <?php echo if ($this_month == 'Jun') echo 'selected'; ?>>Jun</option>	
    <option value="7" <?php echo if ($this_month == 'Jul') echo 'selected'; ?>>Jul</option>	
    <option value="8" <?php echo if ($this_month == 'Aug') echo 'selected'; ?>>Aug</option>
    <option value="9" <?php echo if ($this_month == 'Sep') echo 'selected'; ?>>Sep</option>	
    <option value="10" <?php echo if ($this_month == 'Oct') echo 'selected'; ?>>Oct</option>	
    <option value="11" <?php echo if ($this_month == 'Nov') echo 'selected'; ?>>Nov</option>	
    <option value="12" <?php echo if ($this_month == 'Dec') echo 'selected'; ?>>Dec</option>
                    </select>

Parse error: parse error in C:\wamp\www\28_09_pm_new\profile edit.php on line 932 (here line 2)

<select name="month" id="month">	<option value="1" <?php echo if ($this_month == 'Jan') echo 'selected'; ?>>Jan</option>	<option value="2" <?php if ($this_month == 'Feb') echo 'selected'; ?>>Feb</option>	<option value="3" <?php echo if ($this_month == 'Mar') echo 'selected'; ?>>Mar</option>	<option value="4" <?php echo if ($this_month == 'Apr') echo 'selected'; ?>>Apr</option>	// etc.</select><select name="month" id="month">
	<option value="1" <?php if ($this_month == 'Jan') echo 'selected'; ?>>Jan</option>
	<option value="2" <?php if ($this_month == 'Feb') echo 'selected'; ?>>Feb</option>
	<option value="3" <?php if ($this_month == 'Mar') echo 'selected'; ?>>Mar</option>
	<option value="4" <?php if ($this_month == 'Apr') echo 'selected'; ?>>Apr</option>
	// etc.
</select>

echo after <php is not needed...
stated as above...

Thanx Pritaeas...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.