I'm getting data from my database, i want to show one field into a dropdown menu and the rest(according to the selected user in the dropdown menu) in a paragraph below it as im trying to do in the code below, what is missing please?
<div class="w3-display-bottomleft w3-container w3-text-black">
<?php
echo "<select name='users' id='users' placeholder='Employee'>";
while ($row = mysqli_fetch_array( $result, MYSQLI_ASSOC)) {
echo "<option value='" . $row['id'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";
echo"</div>";
echo"</div>";
echo"<div class='w3-container'>";
while ($row = mysqli_fetch_array( $result, MYSQLI_ASSOC)) {
echo "<p><i class='fa fa-briefcase fa-fw w3-margin-right w3-large w3-text-teal'></i>". $row['department'] ."</p>";
echo "<p><i class='fa fa-home fa-fw w3-margin-right w3-large w3-text-teal'></i>Malta</p>";
echo "<p><i class='fa fa-envelope fa-fw w3-margin-right w3-large w3-text-teal'></i>user@email.com</p>";
}
?>
<hr>
I have now tried with a foreach loop, but i need it to only display the data of the selected user. How can i do that? (code below)
<div class="w3-display-bottomleft w3-container w3-text-black">
<?php
$my_rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
echo "<select name='users' id='users' placeholder='Employee'>";
foreach($my_rows as $row) {
echo "<option value='" . $row['id'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";
echo"</div>";
echo"</div>";
echo"<div class='w3-container'>";
foreach($my_rows as $row) {
echo "<p value='" . $row['id'] ."'><i class='fa fa-briefcase fa-fw w3-margin-right w3-large w3-text-teal'></i>". $row['department'] ."</p>";
echo "<p><i class='fa fa-home fa-fw w3-margin-right w3-large w3-text-teal'></i>Malta</p>";
echo "<p><i class='fa fa-envelope fa-fw w3-margin-right w3-large w3-text-teal'></i>user@email.com</p>";
}
?>
<hr>