<?php 
require('db.php');
include("auth.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="index.php">Home</a> | <a href="insert.php">Insert New Record</a> | <a href="logout.php">Logout</a></p>
<h2>View Records</h2>
<table width="60%"  border="1px;" style="border-collapse:collapse;">
<tr>
<th><strong>Picture</strong></th>
<th><strong>Plant Name</strong></th>
<th><strong>Soil</strong></th>
<th><strong>Fertility</strong></th>
<th><strong>Water</strong></th>
<th><strong>Sunlight</strong></th>
<th><strong>Planting Date</strong></th>
<th><strong>Days to Germinate</strong></th>
<th><strong>Days to harverst</strong></th>
<th><strong>Edit</strong></th>
<th><strong>Delete</strong></th>
</tr>
<?php
$count=1;
$sel_query="Select Plants.picture, Seeds.germination, Seeds.water, Seeds.fertility, Seeds.soil, Seeds.sunlight, Seeds.days_to_harvest, Planted.plant_name, Planted.id, Plants.id, Seeds.id, Planted.planted_date from Planted, Seeds, Plants WHERE Planted.plant_name=Seeds.plant_name AND Plants.plant_name=Seeds.plant_name";
$result = mysql_query($sel_query);




while($row = mysql_fetch_assoc($result)) {
$now = time();
$your_date = strtotime($row["planted_date"]);
$datediff = $now - $your_date;
$day_from_now = floor($datediff/(60*60*24));

$Remaining_days_germinate = $row["germination"] - $day_from_now;
if ($Remaining_days_germinate < 0) { $Remaining_days_germinate = 0; }

$Remaining_days_harvest = $row["days_to_harvest"] - ( $day_from_now +  $row["germination"]);

if ($Remaining_days_harvest < 0) { $Remaining_days_harvest = 0; }
 ?>
<tr>
<td align="center"><img src="../Plant_images/<?php echo $row["picture"]; ?>.gif" style="height:80px;"></td>
<td align="center"><?php echo $row["plant_name"]; ?></td>
<td align="center"><?php echo $row["soil"]; ?></td>
<td align="center"><?php echo $row["fertility"]; ?></td>
<td align="center"><img src="../Images/<?php echo $row["water"]; ?>.png" style="height:80px;"></td>
<td align="center"><img src="../Images/<?php echo $row["sunlight"]; ?>.png" style="height:80px;"></td>
<td align="center"><?php echo $row["planted_date"]; ?></td>
<td align="center"><?php echo $Remaining_days_germinate ; ?></td>
<td align="center"><?php echo $Remaining_days_harvest; ?></td>
<td align="center"><a href="edit.php?id=<?php echo $row["id"]; ?>">Edit</a></td>
<td align="center"><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a></td>
</tr>
<?php $count++; } ?>
</table>
</div>
</body>
</html>
