Jump to content

[SOLVED] Adding no date in drop down


dc_jt

Recommended Posts

*****Just realised I have rambled on a bit below, I basically just want the drop down to display the -- for day, month and year when there is already a date set. It works when there isnt a date set but when there is, it only displays the numbers!! *****

 

Hi I have got the following drop down called End Date.

 

When someone adds an offer I want the end date to be set to -- -- ---- (which it does perfectly). With the other days, months and years available to be selected.

 

When someone comes to edit an offer, I want the end date to show the date that has been set for this offer previously. Therefore, if an offer ends on 31/05/2007 the drop down is set to 31-05-2007 (which this also does perfectly) HOWEVER the slashes (-- -- ----) for day, month and year do not appear, only the days (1-31), months (1-12) and years (2006-2009).

 

How can I get this to show the slashes when I edit the offer as well as the set date???

 

Please someone help, it has took me a long time getting here (and a long time writing this also)

 

Here is the code for when you are editing an offer which already has an end date set :

 

Day

<?
if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000')
{
for ($i=1;$i<=31;$i++)
{?><?
echo "<option value=\"$i\"";

	if ($i == $EndaDay) echo " selected";
	echo ">".printf(">%02d</option>",$i);
} 

 

Month

<? 
if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000')
{
for ($i=1;$i<=12;$i++)
{?><?
echo "<option value=\"$i\"";

	if ($i == $EndaMonth) echo " selected";
	echo ">".printf(">%02d</option>",$i);
} 

}

 

Year

<?php

if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000')
{
	for ($i=date('Y')-1;$i<=date('Y')+2;$i++)
	{
	echo "<option value=\"$i\"";

	if ($i == $EndaYear) echo " selected";

	echo ">".printf(">%02d</option>",$i);
	}
}

 

The above means there is a date already set (formatDate($oObj->end_date) != '00/00/0000')

 

The rest of my code is:

 

This is to get the date if there is already one set in database

/***** End Date *****/
$Enddate = str_replace(" ","/",formatDate($oObj->end_date));
$EndaDate = explode("/",$Enddate);

$EndaYear = (int)$EndaDate[2];
$EndaMonth =(int)$EndaDate[1];
$EndaDay = (int)$EndaDate[0];
/************************/

 

This is the whole loop:

 

<strong>End Date</strong></td>
<td><select name="Endsdated" class="fmgreynormal">  
<?
if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000')
{
for ($i=1;$i<=31;$i++)
{?><?
echo "<option value=\"$i\"";

	if ($i == $EndaDay) echo " selected";
	echo ">".printf(">%02d</option>",$i);
} 

} else {
	 for ($i=1;$i<=31;$i++)
	{
		echo "<option value=\"$i\">$i</option>";
	}
		echo "<option value=\"--\" selected>--</option>";
}
?>
</select>

<select name="Endsdatem" class="fmgreynormal">  
<? 
if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000')
{
for ($i=1;$i<=12;$i++)
{?><?
echo "<option value=\"$i\"";

	if ($i == $EndaMonth) echo " selected";
	echo ">".printf(">%02d</option>",$i);
} 

} else {
for ($i=1;$i<=12;$i++)
	{
		echo "<option value=\"$i\">$i</option>";
	}
		echo "<option value=\"--\" selected>--</option>";
}
?>
</select> 
  
<select name="Endsdatey" class="fmgreynormal"> 
  <?php

if ($_GET['iOfferId'] && formatDate($oObj->end_date) != '00/00/0000')
{
	for ($i=date('Y')-1;$i<=date('Y')+2;$i++)
	{
	echo "<option value=\"$i\"";

	if ($i == $EndaYear) echo " selected";

	echo ">".printf(">%02d</option>",$i);
	}
} else {
	for ($i=date('Y')-1;$i<=date('Y')+2;$i++) 
	{
		echo "<option value=\"$i\">$i</option>";
	}
		echo "<option value=\"--\" selected>--</option>";
}
?>

</select> 

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.