Based on the selection of dates how can I display the information stored in database

<?php

$month_array = array( "January", "February", "March", "April", "May", "June",
                      "July", "August", "September", "October", "November", "December");

echo "<select name=\"day\">";
$i = 1;
while ( $i <= 31 ) {
   echo "<option value=".$i.">".$i."</option>";
   $i++;
}
echo "</select>";

echo "<select name=\"month\">";
$i = 0;
while ( $i <= 11 ) {
   echo "<option value=".$i.">".$month_array[$i]."</option>";    
   $i++;
}
echo "</select>";

echo "<select name=\"year\">";
$i = 1900;
while ( $i <= 2007 ) {    
   echo "<option value=".$i.">".$i."</option>";    
   $i++;
}
echo "</select>";

?>

Hard to say, it depends on what information is in your database. Once you’ve selected the day, month and year you can use the information in a query to get data out, but exactly how will depend on what information and in what format is it stored.

The information is text based information…the information that I want to display is getting displayed but as a separate file.I am not sure like how should I embed my mysql statements.

select foo from bar where storeddate = '$year-$month-$day'

Thanks bro…But my another question which might sound foolish or silly is where should use this statement?i.e whether I should include this statement in the code which connects to the database?

<html>
<head>
<body><br>

date:<input type="date" value=" ">
<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$date = date(" Y-m-d"); 
echo "$date <br>";

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT `date`,`Comments` FROM `details`WHERE `Comments`="shahrukh"  '  ;


mysql_select_db('information');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
    echo  "comments: {$row[1]} <br> ".
       "date {$row[0]} <br>".
         "--------------------------------<br>";
}
mysql_free_result($retval);
echo "Fetched data successfully\n";
mysql_close($conn);
?>
</boddy>
</html>

This is my connecting to database code…I know I should be using PDO but right now this code is working…My question where should I insert the statement suggested by you…Should I use loop or for statements?

`SELECT `date`,`Comments` FROM `details`WHERE `Comments`="shahrukh" and yourdatetiemcoulmn = "2017-01-07"`

Ya…This works but the problem is I shud change it manually right…everytime

No, instead of the date string in the sample code, you use the date string that comes from your input form, as in @chorn’s example in #4.

To be more clearer I have a form which also displays a calendar using the code
date:…I have another form where the information will already be stored in database…Now if I want the data to be displayed based on the selection of date how can it be done?

You mean to say I shud be using this code rather select foo from bar where storeddate = ‘$year-$month-$day’

This is the key part, it uses the year month and day from your input page to select the data. So you’d use those variables in your query, instead of the hard-coded date.

$sql = 'SELECT date,Comments FROM detailsWHERE Comments=“shahrukh”,date= ‘$year-$month-$day’ ’ ;

This is displaying internal server error…

the whole code…

<html>
<head>
<body><br>

date:<input type="date" value=" ">
<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$date = date(" Y-m-d"); 
echo "$date <br>";

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT `date`,`Comments` FROM `details`WHERE `Comments`="shahrukh",`date`= '$year-$month-$day' '  ;


mysql_select_db('information');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
    echo  "comments: {$row[1]} <br> ".
       "date {$row[0]} <br>".
         "--------------------------------<br>";
}
mysql_free_result($retval);
echo "Fetched data successfully\n";
mysql_close($conn);
?>
</boddy>
</html>

Well, it would.

$sql = 'SELECT date,CommentsFROMdetailsWHEREComments="shahrukh",date= '$year-$month-$day' ' ;

If you want to just stick variable names inside a PHP string, you need to surround it with double quotes, not single quotes. I think the SQL syntax won’t like the way you’ve formatted the query either. Does this work any better?

$sql = "SELECT date,Comments FROM details WHERE Comments = 'shahrukh' and date= '$year-$month-$day' ";

You are calling this from your code posted in your opening post, aren’t you? And getting the form variables, validating them, and parsing from the $_POST array into the variables you use in the query?

$sql = "SELECT date,Comments FROM details WHERE Comments = ‘shahrukh’ and date= ‘$year-$month-$day’ ";
This is working and moreover I have included a submit option but still the information from database is not getting displayed…Where as if I remove the date= ‘$year-$month-$day’ ";it is displaying but that is not a particular date…displays all that contains Comments=“shahrukh”

OK, so what type of column is your date stored in, and in what format? Is it a date or datetime column, or a text or varchar used to store a date? Bringing nothing out suggests that the format may not be YMD, so maybe it will need to be tailored to suit. Show some sample dates as they appear if you remove that condition.

field name is date and type is date…And in the database it displays in Y-m-d…i.e 2017-01-25

Sounds as if it should work. Can you show your latest code, in case there’s a typo or something where you take the form variables into the query.

<html>
<head>
<body><br>

date:<input type="date" value=" ">
<input type="submit" value="submit"/>
<?php
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
$date = date(" Y-m-d"); 
echo "$date <br>";

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = "SELECT date,Comments FROM details WHERE Comments = 'shahrukh' and date= '$year-$month-$day'  ";


mysql_select_db('information');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
    echo  "comments: {$row[1]} <br> ".
       "date {$row[0]} <br>".
         "--------------------------------<br>";
}
mysql_free_result($retval);
echo "Fetched data successfully\n";
mysql_close($conn);
?>

</body>
</html>

It is not displaying the information stored in database when I select a particular date and submit it…Confused