How to display all from drop down search menu

<?php

//This creates the drop down box

echo "<select name= 'site'>";
echo '<option value="">'.'All'.'</option>';

//$query=mysqli_query($db,"SELECT site FROM nov");

$query = mysqli_query($db,"SELECT site FROM nov GROUP BY site");

$query_display = mysqli_query($db,"SELECT * FROM nov");

while($row=mysqli_fetch_array($query))
{
     echo "<option value='". $row['site']."'>".$row['site']
 .'</option>';

}

echo '</select>';

?>  	     <br /><br />    <label for="month"><b>Month &nbsp  : </b></label> &nbsp  
<?php

//This creates the drop down box

echo "<select name= 'month'>";
echo '<option value="">'.'All'.'</option>';

//$query=mysqli_query($db,"SELECT site FROM nov");

$query = mysqli_query($db,"SELECT monthname(date) FROM nov GROUP BY monthname(date)");

$query_display = mysqli_query($db,"SELECT * FROM nov");

while($row=mysqli_fetch_array($query))
{
     echo "<option value='". $row['monthname(date)']."'>".$row['monthname(date)']
 .'</option>';

}

echo '</select>';

?>  	     <br /><br /> <label for="year"><b>Year &nbsp  : </b></label>  &nbsp 
<?php

//This creates the drop down box

echo "<select name= 'year'>";
echo '<option value="">'.'All'.'</option>';

//$query=mysqli_query($db,"SELECT site FROM nov");

$query = mysqli_query($db,"SELECT year(date) FROM nov GROUP BY year(date)");

$query_display = mysqli_query($db,"SELECT * FROM nov");

while($row=mysqli_fetch_array($query))
{
     echo "<option value='". $row['year(date)']."'>".$row['year(date)']
 .'</option>';

}

echo '</select>';

?> 	     <br /><br /><input type="submit" name="submit" value="Search"/>
</form>

Open in new window

This is my dropdownsearch.php

<?php 

if(isset($_POST['submit']))
{

$site = $_POST['site'];
$mdate = $_POST['month'];
$ydate = $_POST['year'];

$sql = "SELECT * FROM nov WHERE site = '".$site."' and monthname(date) = '".$mdate."' and year(date) = '".$ydate."'";
if($result = mysqli_query($db, $sql)){
    if(mysqli_num_rows($result) > 0){
        echo "<table width='100%' style = 'border-collapse:collapse'>";
            echo "<tr>";
			                echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Date</th>";
                echo "<th style = 'width:20px;border:1px solid black' align = 'center'>File Name</th>";
                echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Site</th>";
                echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Name</th>";
                echo "<th style = 'width:20px;border:1px solid black' align = 'center'>CPU Count</th>";
				echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Memory Size</th>";
				echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Disk Space Size</th>";
				echo "<th style = 'width:20px;border:1px solid black' align = 'center'>NIC Count</th>";
				echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Power State</th>";
				echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Memory Size INGB</th>";
				echo "<th style = 'width:20px;border:1px solid black' align = 'center'>Disk Space Size INGB</th>";
            echo "</tr>";
        while($data = mysqli_fetch_array($result)){
            echo "<tr>";
                echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[0] . "</td>";
                echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[1] . "</td>";
                echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[2] . "</td>";
                echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[3] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[4] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[5] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[6] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[7] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[8] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[9] . "</td>";
				echo "<td style = 'width:20px;border:1px solid black' align = 'center'>" . $data[10] . "</td>";
            echo "</tr>";
        }
        echo "</table>";
        // Free result set
        mysqli_free_result($result);
    } else{
        echo "No records matching your query were found.";
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
}

}
?>

<!--</table>
</td>
</tr>
</table>-->
<br/>
</div>
	<div class="footer" style="background-color:#778899">
	   <form action="updatesite.php" method="post" enctype="multipart/form-data">
   <button type="submit" name="btn-return" style="display: inline;">&laquo; Return</button>
    </form>
	   <form action="index.php" method="post" enctype="multipart/form-data">
   <button type="submit" name="btn-main" style="display: inline;">Main Page</button>
    </form>

Open in new window

This my dropdownfunction.php

but now i having a question , how i display all the data when i select all ..
Capture.PNG
Capture2.PNG
Scott Yong Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Try this

$site = isset($_POST['site']) ? $_POST['site']: false;
$mdate = isset($_POST['month']) ? $_POST['month'] : false;
$ydate = isset($_POST['year']) ? $_POST['year'] : false;

$sql = "SELECT * FROM nov WHERE site = '{$site}'";
if ($mdate) {
  $sql .= " and monthname(date) = '{$mdate}'"
}
if ($ydate) {
  $sql .= " AND YEAR(date) = '{$ydate}'";
}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
having error on Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\db_v4\updatesite_test.php on line 80
You deleted the comment so I am assuming you saw the missing ';' on that line.
0
Scott Yong Author Commented:
? $_POST['year'] : false; what does this mean sir?
0
Julian HansenCommented:
It is a ternary expression and is the same as
if (isset($_POST['year']) {
   $year = $_POST['year']
}
else {
  $year = false;
}

Open in new window

It is a short hand way of an if / then / else where ? is for the TRUE part and : is for the false part
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.