PHP combo
Posted: Mon Jul 25, 2016 2:53 am
Hi
I have a combo that I want to fill with data from a table.
Heres my code:
My test.php looks like this:
However the combobox is not filled. I have tried the mysql query, and that works. The problem has to be with the list in the combo. Any suggestions?
I have a combo that I want to fill with data from a table.
Heres my code:
Code: Select all
<html>
<?php
include './config/config.php';
include './config/opendb.php';
$query_disp="SELECT DISTINCT
Responsible as respons
FROM RegTable";
$result_disp = mysql_query($query_disp, $conn);
include './config/closedb.php';
?>
<h2>Responsible:</h2>
<form action="test.php" method="POST">
<select name="responsible">
<?php foreach ($result_disp as $key => $value) : ?>
<?php $selected = ($key == $_POST['respons']) ? 'selected="selected"' : ''; ?>
<option value="<?php echo $key ?>" <?php echo $selected ?>>
<?php echo $value ?>
</option>
<?php endforeach; ?>
</select>
<input type="submit" value="Vis liste">
</form>
</html>
Code: Select all
<?php
$respons = $_POST['responsible'];
include './config/config.php';
include './config/opendb.php';
$result = mysql_query("SELECT * FROM RegTable WHERE Responsible = '$respons' ORDER BY Date DESC")
or die(mysql_error());
echo "<table border='0'>";
echo "<tr><th>Dato</th><th>Registrert av</th><th>Telefon</th><th>Mobil</th><th>Kundenavn</th><th>Kontaktperson</th><th>Endring</th></tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr><td>";
echo date('d.m.Y', strtotime($row['Date']));
echo "</td><td>";
echo $row['Responsible'];
echo "</td><td>";
echo $row['Phone'];
echo "</td><td>";
echo $row['Mobile'];
echo "</td><td>";
echo $row['CustName'];
echo "</td><td>";
echo $row['ContactName'];
echo "</td><td>";
?>