Tedd's Demo for Lauren
The Activity is: "Leaf" It To Cabbage!
CODE FOLLOWS
<?php
// this is the second part (ajax-demo-a.php)
// this part does all the work
session_name("sperlt");
session_start(); // establish, or continue, a session
$plant = !empty($_SESSION['plant']) ? $_SESSION['plant'] : null;
$setting = !empty($_SESSION['setting']) ? $_SESSION['setting'] : null;
$length = !empty($_SESSION['length']) ? $_SESSION['length'] : null;
$plant_table = 'aplants';
$settings_table = 'asettings';
$activityLength_table = 'aactivity_lengths';
$activities_table = 'aactivities';
$plants = array();
$settings = array();
$activityLengths = array();
$activities = array();
$con = '';
$activity = '';
include('../includes/open-db.php'); //====== open dB
$query = "SELECT * FROM $plant_table WHERE id > '0' ";
$result = mysqli_query($con, $query) or die("could not open table1");
while ($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$plants[$id] = htmlentities($row['name']);
}
$query = "SELECT * FROM $activityLength_table WHERE id > '0' ";
$result = mysqli_query($con, $query) or die("could not open table3");
while ($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$activityLengths[$id] = htmlentities($row['name']);
}
$query = "SELECT * FROM $settings_table WHERE id > '0' ";
$result = mysqli_query($con, $query) or die("could not open table4");
while ($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$settings[$id] = htmlentities($row['name']);
}
$query = "SELECT * FROM $activities_table WHERE id > '0' ";
$result = mysqli_query($con, $query) or die("could not open table2");
while ($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$activities[$id] = htmlentities($row['name']);
}
include('../includes/close-db.php'); //====== close dB
$select_plants = isset($_GET['plants']) ? $_GET['plants'] : 1;
$select_settings = isset($_GET['settings']) ? $_GET['settings'] : 1;
$select_activityLengths = isset($_GET['activityLengths']) ? $_GET['activityLengths'] : 1;
$url = 'ajax-demo-a.php';
$plant = $select_plants;
$setting = $select_settings;
$length = $select_activityLengths;
$_SESSION['plant'] = $plant;
$_SESSION['setting'] = $setting;
$_SESSION['length'] = $length;
// first activity condition
if ($plant == 2 && $setting == 2 && $length == 3)
{
$activity = $activities[1];
}
// second activity condition
if ($plant == 2 && $setting == 1 && $length == 1)
{
$activity = $activities[2];
}
// third activity condition
if (($plant == 3 && ($setting == 1 || $setting == 2) && $length == 2))
{
$activity = $activities[3];
}
// fourth activity condition
if ($plant == 1 && $setting == 1 && $length == 1)
{
$activity = $activities[4];
}
?>
<br>
<label for="plants">Select Plant</label>
<SELECT id="plants" name="plants" onchange="get(this.parentNode, '<?php echo($url); ?>');">
<?php
foreach ($plants as $key => $value)
{
$selected = '';
if ($key == $select_plants)
{
$selected = 'selected';
}
echo("<option value=$key $selected >$value");
}
?>
</SELECT>
<br>
<label for="plants">Select Setting</label>
<SELECT id="settings" name="settings" onchange="get(this.parentNode, '<?php echo($url); ?>');">
<?php
foreach ($settings as $key => $value)
{
$selected = '';
if ($key == $select_settings)
{
$selected = 'selected';
}
echo("<option value=$key $selected >$value");
}
?>
</SELECT>
<br>
<label for="plants">Select Activity Length</label>
<SELECT id="activityLengths" name="activityLengths" onchange="get(this.parentNode, '<?php echo($url); ?>');">
<?php
foreach ($activityLengths as $key => $value)
{
$selected = '';
if ($key == $select_activityLengths)
{
$selected = 'selected';
}
echo("<option value=$key $selected >$value");
}
?>
</SELECT>
<p>
The Activity is: <?php echo($activity);?>
</p>
<br>
<div class="clear">
</div>
<?php // show code
echo("<div id=\"margin\">");
$self = "ajax-demo-a.php";
echo('<hr>CODE FOLLOWS<br><br>');
ini_set('highlight.comment', '#800000; font-weight: bold;');
highlight_file($self);
echo('<hr>');
echo('</div>');
?>