Stefan Schneider
Stefan Schneider

Reputation: 157

How to print one array value of an PDO database select query?

I am using this PDO wrapper class: http://www.imavex.com/php-pdo-wrapper-class/#select and now just have troubles to echo an object.

This is the method declaration:

<?php
//select Method Declaration
public function select($table, $where="", $bind="", $fields="*") { }
?>

My query goes like this which prints the result array:

<?php
$title = 'title_'.$GLOBALS['SelectedLang'];

$results = $GLOBALS['db']->select("news", $title != '', "", $title);
print_r($results);
?>

But how do I echo one table field of the query? Which in old school mysql I would have done like this:

<?php
$row = @mysql_query($results);
echo $row->$title;
?> 

The output for the print_r is: Array ( [0] => Array ( [title_en] => englisch ) )

Upvotes: 0

Views: 1662

Answers (1)

v0d1ch
v0d1ch

Reputation: 2748

So if you want to echo your query results you should do it in a loop:

foreach($results as $r){echo $r['title_en'];}

Upvotes: 4

Related Questions