Reputation: 21
I created a method for returning a certain row and there is no error or anything just the method not returning any data from the database.
Here is where I invoke the method:
<a class="navbar-brand" href="http://localhost/old marketplace website/">
<?php echo $controller->getTableData($table, $column, $columnValue, $rowTitle); ?>
</a>
And here is what the method getTableData()
looks like:
public function getTableData($table, $column, $columnValue, $rowTitle)
{
$query = $this->db->prepare("SELECT * FROM $table WHERE $column = ? ");
$query->bindValue(1,$columnValue);
$query->execute();
$f = $query->fetch(PDO::FETCH_ASSOC);
$result = $f['$rowTitle'];
return $result;
}
How do I need to adjust my method to have it return the desired data?
Upvotes: 2
Views: 71
Reputation: 421
Try removing quotes from the following line:
$result = $f['$rowTitle'];
You're looking for a column with the name equal to the value of $rowTitle
, rather than a column with the name '$rowTitle'
. Remove the single quotes to use the value of the variable $rowTitle
:
$result = $f[$rowTitle];
For reference, see:
Upvotes: 5