Im a newbie to this forum and have just started coding in php. Need some help. I have the following code
require_once('/mysql/sql_connect.php');
$q = "SELECT pty.pty_profile_name AS profile FROM pty, users WHERE users.username = 'testaccount' ";
$r = @mysqli_query ($dbc, $q);
$results_array = array();
while($row = mysqli_fetch_assoc($r)) {
array_push($results_array, $row);
echo "
"; print_r($results_array); echo ""; }
?>
Select Property
<?php foreach($results_array as $key => $value){ ?>
if (isset($_POST['Submit'])) {
echo "
"; echo ($_POST['pty_select']); echo ""; } ?>
The output I get is correct, but it displays the key, eg, 0 or 1 or 2, based on what I select in the form. I need the value output. Eg 0 = Emerton, it outputs "0" instead of Emerton.
If I echo $value['profile'] instead of pty_select, I get the last result of the query all the time. Which in this example would be 2, which is Ambarvale as I believe it just chooses the last row output of the query.
I hope I've made sense. Thanks in advance.
解决方案
You mean you need the value what you have used to display it.
Then,
Change to :