Link to home
Start Free TrialLog in
Avatar of Yong Scott
Yong ScottFlag for Malaysia

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of Yong Scott

ASKER

? $_POST['year'] : false; what does this mean sir?
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