Reputation: 155
I am showing a <select>
list, and I want to retrieve the id
column without showing it in the list:
public function view_expenses($username) {
$query = $this->db->prepare("SELECT * FROM `expenses` WHERE `username`= ?");
$query->bindValue(1, $username);
$i = 0;
$selectedId = 0;
try{
$query->execute();
foreach ($query as $row) {
$month = $row['date'];
$i++;
echo "<option>".$i.") Amount: ".$row['amount']."$, Type: ".$row['type'].", Month: ".$month."</option>";
$selectedId = $row['id'];
}
$this->queryResult = $query->fetch();
$this->selectedId = $selectedId;
} catch(PDOException $e){
die($e->getMessage());
}
}
I have the $selectedId
to retrieve the id, but I'm not sure how to get it from my other page.
I am using this to show the select options:
<?php
$users->view_expenses($username);
?>
I am including the user.php file in my other php files to retrieve all this functions results. How do I appeal it from outside to get the selectedId without showing it anywhere and use it for later functions ?
Upvotes: 0
Views: 64
Reputation: 6296
echo "<option value='".$i."'> Amount: ".$row['amount']."$, Type: ".$row['type'].", Month: ".$month."</option>";
Upvotes: 0
Reputation: 1477
echo "<option value=".$row['id'].">".$i.") Amount: ".$row['amount']."$, Type: ".$row['type'].", Month: ".$month."</option>";
Upvotes: 1
Reputation: 943563
Set a value
attribute on the <option>
element. It will override the text node child of the element for the purposes of determining what data will be submitted to the server (but not for determining what will be rendered in the drop down menu UI).
Upvotes: 1