简体   繁体   中英

method not returning anything

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM