Forum Moderators: coopster

Message Too Old, No Replies

how to get the Default date in the drop box

help with getting default date in drop down

         

shruti

2:58 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



I have a page called comments.html
I select date from the drop down and then when I click submit then the php file (datecomments.php) gets the comments made by users on that date by comparing the date field.

Now, all I want to do is to get the default date to the sytem date everyday.
Like the default date(d-m-y) in the drop down should be todays.

I dont want to change the whole code coz then it messes up the database and thus many other stuff too.
Please can you help with this problem.

I will be very greatful.
Thanks in advance.

my html page is comments.html
body code:

<body>

<p>&nbsp;</p>
<p>&nbsp;</p>
<form method=post name=f1 action='datecomments.php'>
<p align="center" class="style1">
<input type=hidden name=todo value=submit />
PLEASE SELECT A DATE</p>
<table width="367" border="0" align="center" cellspacing="0" bordercolor="#CC0066" >
<tr><td width="113" align=left ><div align="center">
<select name="month" id="month" value='MONTH' style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option>----Month----</option>


Select Month



<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
</div></td>
<td width="84" align=left > <select name="date" id="date" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option selected="selected">--Date--</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select></td><td width="164" align=left ><label>
<select name="year" id="year" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option selected="selected">----Year----</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
</select>
</label>
<input type=submit id="submit" class="formbutton" value=Submit>
</table>

.<style type="text/css">

.formbutton{
cursor:pointer;
border:outset 3px #ccc;
background:#999;
color:#666;
font-weight:bold;
padding: 2px 5px;
background:url(media/formbg.gif) repeat-x left top;
}

</style>
<div align="center"></div>
</form>
</body>

======================================================================

And my php code is :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
background-image: url(02.jpg);
}
.style1 {
color: #CC0066;
font-weight: bold;
font-family: Georgia, "Times New Roman", Times, serif;
}
-->
</style></head>

<body>

<form action="" method="post" name="form1" class="style1" id="form1">

<div align="center">-------ALL THE COMMENTS ------ </div>
</form>

<p>&nbsp;</p>
<p>
<?php
GLOBAL $dt,$mth,$yr;

$host = "localhost";
$user = "";
$pass = "";
$dbname = "";

$connection = mysql_connect("localhost", "root", "") or die("Cannot connect to MySQL server: " . mysql_error());
$db_selected = mysql_select_db('tmetrix', $connection);

$CurrDay=date("d");
$CurrMonth=date("m");
$CurrYear=date("Y");

$mth=$CurrMonth;
$dt=$CurrDay;
$yr=$CurrYear;

$mth = $_POST['month'];
$dt = $_POST['date'];
$yr = $_POST['year'];

$whole1="$yr-$mth-$dt";

echo " You have Selected date:$whole1";

$data = mysql_query("SELECT * FROM comments where date = '$whole1'");
Print "<table border=2 cellspacing=2 align=center bordercolor=#FFffff cellpadding=10 width=761 style='bordercolor:#CC0066;font-family:Courier New;color:#CC0066'>";

$num_data = mysql_num_rows($data);
echo "<tr><td bgcolor='#E2C6FF' style='width:70.75pt;font-weight:bold;padding:0in 0in 0in 0in'>CELLID</td> ";
echo "<td bgcolor='#E2C6FF' style='width:70.75pt;font-weight:bold;padding:0in 0in 0in 0in'>PROBLEM</td> ";
echo "<td bgcolor='#E2C6FF' style='width:70.75pt;font-weight:bold;padding:0in 0in 0in 0in'>SOLUTION</td> ";
echo "<td bgcolor='#E2C6FF' style='width:70.75pt;font-weight:bold;padding:0in 0in 0in 0in'>COMMENTS</td></tr> ";

for ($i=0; $i <$num_data; $i++)
{

$row = mysql_fetch_array($data);

echo "<tr><td>" .$row['CELLID'] . "</td> ";
echo "<td>" .$row['problem'] . "</td> ";
echo "<td>" .$row['solution'] . "</td> ";
echo "<td>" .$row['comments'] . "</td></tr> ";

}

?>



</p>
</body>
</html>

[edited by: eelixduppy at 2:59 pm (utc) on July 15, 2008]
[edit reason] disabled smileys [/edit]

mrscruff

3:33 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



Just quick one, could change comments.html to comments.php and use for loops to generate each option value, and use simple if statement to check if is curent, if so add selected="selected" i.e

//for month
if ($value == date(m)) echo 'selected="selected"';

gcarn

3:35 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



so you want to make sure the date on the html page populated with todays date?

This would be easy if it were made in php,
In a for loop, you would create the select options,
then you could do a fast easy compare right there in the loop to set it as selected.

[edit] - Looks like i got beat to it!

shruti

4:03 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



can you please explain in details......
which part of the php code should i put on comments?

shruti

6:33 pm on Jul 15, 2008 (gmt 0)

10+ Year Member



I am sorry but can you explain me which part of my php code should i put in the html page and how it will work?

Apologies as i am in a process of learning php.

Sorry

mrscruff

11:25 am on Jul 16, 2008 (gmt 0)

10+ Year Member



comments.html will need to be comments.php and any link to the page updated. And the following should do what you want :)

<body>

<p>&nbsp;</p>
<p>&nbsp;</p>
<form method="post" name="f1" action="datecomments.php">
<p align="center" class="style1">
<input type="hidden" name="todo" value="submit" />
PLEASE SELECT A DATE</p>
<table width="367" border="0" align="center" cellspacing="0" bordercolor="#CC0066" >
<tr><td width="113" align="left" ><div align="center">
<select name="month" id="month" value="MONTH" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option>----Month----</option>

Select Month
<?php
$this_month = date('m');
$month = array('01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');
for ($x=1; $x<=12; $x++) {
$selected = '';
if (strlen($x) == 1) {
$x = '0'.$x;
if ($x == $this_month) $selected = 'selected="selected"';
} else {
if ($x == $this_month) $selected = 'selected="selected"';
}
echo '<option value="'.$x.'" '.$selected.'>'.$month[$x].'</option>';
}
?>

</select>
</div></td>
<td width="84" align="left" > <select name="date" id="date" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option>--Date--</option>
<?php
$this_day = date('d');
for ($x=1; $x<=31; $x++) {
$selected = '';
if (strlen($x) == 1) {
$x = '0'.$x;
if ($x == $this_day) $selected = 'selected="selected"';
} else {
if ($x == $this_day) $selected = 'selected="selected"';
}
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
}
?>
</select></td><td width="164" align="left" ><label>
<select name="year" id="year" style="background: pink; color: black; text-decoration; none; border: 1px solid white;">
<option>----Year----</option>
<?php
$this_year = date('Y');
for ($x=2007; $x<=2009; $x++) {
$selected = '';
if ($x == $this_year) $selected = 'selected="selected"';
echo '<option value="'.$x.'" '.$selected.'>'.$x.'</option>';
}
?>
</select>
</label>
<input type=submit id="submit" class="formbutton" value="Submit">
</table>

.<style type="text/css">

.formbutton{
cursor:pointer;
border:outset 3px #ccc;
background:#999;
color:#666;
font-weight:bold;
padding: 2px 5px;
background:url(media/formbg.gif) repeat-x left top;
}

</style>
<div align="center"></div>
</form>
</body>

shruti

12:24 pm on Jul 16, 2008 (gmt 0)

10+ Year Member



tons n tons of thanks.....it works.
Thanks.

I am glad that I am a member of webmasterworld.
Thank you.

coopster

1:21 am on Jul 26, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am glad that I am a member of webmasterworld.

So are we :)