Commit bf547b36 authored by alexandru.radulescu's avatar alexandru.radulescu

Uploaded file to get data

parent ff29b8dc
<!DOCTYPE html>
<html>
<head>
<title>Plant Searcher</title>
</head>
</html>
<?php
//ini_set('display_errors', 1); - used for debugging
include ('Connect.php');//include the database connection
$temp = ""; //initialise the temp and light variables
$light= "";
$query = "SELECT TestTemp, TestLight FROM PlantsTest";//first query used to get the temp and light data from the PlantsTest Table
$result = $db->query($query);
if($result->num_rows > 0) //if there is data
{
while($row = $result->fetch_assoc()) { //loop is not really necessary since there is only one entry, but it doesn't hurt
$temp = $row["TestTemp"]; //get the temp and light values from the database
$light = $row["TestLight"];
}
}
if(isset($_POST['update'])) //if the update button is pressed
{
$result = $db->query($query); //repeat the first query
if($result->num_rows > 0)
{
while($row = $result->fetch_assoc()) {
echo "<p><center>Temperature: " . $row["TestTemp"];//print out the current temp and light values to the screen
echo "<br>";
echo "Light: " . $row["TestLight"] . "</center></p>";
$temp = $row["TestTemp"]; //and set the temp and light values again
$light = $row["TestLight"];
}
}
}
$query2 = "SELECT * FROM Plants WHERE Temperature > '".$temp."' AND Light > '".$light."'";
//second query is for getting the plants with a higher temperature and light tolerance than the current ones in the room
if(isset($_POST['plant1']))//if the second button is pressed, start the query
{
$result2 = mysqli_query($db, $query2);
if($result2->num_rows > 0)
{
while($row2 = $result2->fetch_assoc()) { //print out the names of all of the plants with higher temp and light tolerance
echo "<p><center>Plant: " . $row2["Name"] . "</center></p>";
}
}
}
$query3 = "SELECT * FROM Plants WHERE Light < '".$light."' AND Temperature < '".$temp."'";
//the third query is for getting the plants with a lower temperature and light tolerance (the ones who are not suitable for the room)
if(isset($_POST['plant2']))//if the third button is pressed, start the query
{
$result3 = mysqli_query($db, $query3);
if($result3->num_rows > 0)
{
while($row3 = $result3->fetch_assoc()) { //print out the names of the plants
echo "<p><center>Plant: " . $row3["Name"] . "</center></p>";
}
}
}
$search = $_POST['searchText'];//initialise the search variable for the text box
$query4 = "SELECT * FROM Plants WHERE Name = '".$search."' AND Temperature > '".$temp."' AND Light > '".$light."'";
//the fourth query searches for the selected plant and checks if its temperature and light tolerance are high enough
if(isset($_POST['searchButton']))//when the Search button is pressed the query starts
{
$result4 = mysqli_query($db, $query4);
if($result4->num_rows > 0)
{
while($row4 = $result4->fetch_assoc()) { //prints out Yes if the plant is found and if it would survive
echo "<p><center>Yes, " . $row4["Name"] . " will grow well</center></p>";
}
} else //or no, if the plant would not survive
{
echo "<p><center>No, the plant will not grow well</center></p>";
}
}
$db->close();//close the database connection
?>
<form method="POST">
<input type="submit" style ="width: 300px; margin-left: 50%; position:relative; left: -150px" name="update" value="Get Latest Data">
<input type="submit" style ="width: 300px; margin-left: 50%; position:relative; left: -150px" name="plant1" value="Get plants with high Temperature and Light">
<input type="submit" style ="width: 300px; margin-left: 50%; position:relative; left: -150px" name="plant2" value="Get plants with low Temperature and Light">
<p></p>
</form>
<form method="POST">
<input type = "text" style ="width: 290px; margin-left: 50%; position:relative; left: -150px" name ="searchText" value="">
<input type = "submit" style ="width: 300px; margin-left: 50%; position:relative; left: -150px" name = "searchButton" value="Search for plant">
</form>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment