Add exams from exam100 to exam150
This commit is contained in:
40
exam115/index.php
Normal file
40
exam115/index.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
require '/var/www/nikola/practice/exam110/connect.inc.php';
|
||||
?>
|
||||
|
||||
<form action="index.php" method="GET">
|
||||
Choose a food type:
|
||||
<select name="uh">
|
||||
<option value="u">Unhealthy</option>
|
||||
<option value="h">Healthy</option>
|
||||
</select><br><br>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
if (isset($_GET['uh']) && !empty($_GET['uh'])) {
|
||||
$uh = strtolower($_GET['uh']);
|
||||
|
||||
if ($uh == 'u' || $uh == 'h') {
|
||||
|
||||
$query = "SELECT `food`, `calories` FROM `food` WHERE `healthy_unhealthy` = '$uh' ORDER BY `id` DESC";
|
||||
|
||||
if ($query_run = mysqli_query($con, $query)) {
|
||||
if (mysqli_num_rows($query_run) == NULL) { // Ako je broj redova NULL
|
||||
echo "No results fount!";
|
||||
} else {
|
||||
while ($query_row = mysqli_fetch_assoc($query_run)) {
|
||||
$food = $query_row['food'];
|
||||
$calories = $query_row['calories'];
|
||||
|
||||
echo $food . ' has ' . $calories . ' calories.<br>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo 'Query failed.';
|
||||
}
|
||||
} else {
|
||||
echo 'Must be u or h';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user