Apologies and excuse me if my language is not correct, and if this is a novice question.
This is my php code that create a basic dropdown(with the names in the table Sandy,Tom,Tina) which is fed from a php query.
<?php
$servername = "localhost";
$username = "username";
$password = "12345";
$dbname = "dbname";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select * from potluck";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "<select name='list2' id='list2'>";
while($row = $result->fetch_assoc()) {
echo "<option>".$row["name"]."</option>";
}
echo "</select>";
} else {
echo "0 results";
}
$conn->close();
?>
How do I echo to the screen just below the drop down what item was selected?
Or more specifically.
How do I post back to the php db this select * from potluck where name="Sandy";
and then display just below the dropdown what was returned(just a basic string will suffice at this stage)? I am not sure of the ordering of this part and would appreciate any help.
mysql> select * from potluck;
+----+-------+----------------+-----------+-------------+
| id | name | food | confirmed | signup_date |
+----+-------+----------------+-----------+-------------+
| 1 | Sandy | Key Lime Tarts | N | 2012-04-14 |
| 2 | Tom | BBQ | Y | 2012-04-18 |
| 3 | Tina | Salad | Y | 2012-04-10 |
+----+-------+----------------+-----------+-------------+
3 rows in set (0.00 sec)
mysql> select * from potluck where name="Sandy";
+----+-------+----------------+-----------+-------------+
| id | name | food | confirmed | signup_date |
+----+-------+----------------+-----------+-------------+
| 1 | Sandy | Key Lime Tarts | N | 2012-04-14 |
+----+-------+----------------+-----------+-------------+
1 row in set (0.00 sec)
Ref here - might help with my understanding
A simple example of Get working:
<form id="s" method="get">
<select name="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
<?php
if( $_GET["size"])
{
echo "Welcome: ". $_GET['size']. "<br />";
}
?>