Hi There,
I have the following code that I've pieced together from various sources. Neither PHP nor SQL are my main languages, so I'm still learning how this works. I'd like some advice on why this isn't working:
<?php
$con=mysqli_connect("localhost","root","","dwinvoice");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$getPM = "Select Distinct PMName from report";
$results = mysqli_query($con,$getPM)
?>
<select name="select1">
<?php
while ($line = mysql_fetch_array($getPM, MYSQL_ASSOC))
?>
<option value="<?php echo $line['field'];?>"> <?php echo $line['field'];?> </option>
</select>
<?php
$result = mysqli_query($con,"SELECT * FROM report WHERE PMName = $results");
echo "<table border='1'>
<tr>
<th>Track Number</th>
<th>PM Name</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['TrackNumber'] . "</td>";
echo "<td>" . $row['PMName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
I am trying to build a dropdown menu that will pull all distinct names from the PMName column in the table 'report', then take that selection and utilize it in the HTML table down below. I know the syntax here:
$result = mysqli_query($con,"SELECT * FROM report WHERE PMName = $results");
is wrong, but I'm not sure how to make it right. The drop-down list does not actually pull any values, and I'm not sure what I'm doing wrong....