0
votes

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 ) )

1
The statement $title != '' can't be doing what you think it does, btw. The output from your print_r would also be helpful. - MatsLindh
are you able to get back all the titles or is this returning the entire table? Or are you trying to get one specific title? - zazvorniki
well if the function returns object than $results->columnName hardcode second parameter to see if you get results - v0d1ch
If you did print_r($results) and get ['title_en'] as index than you can't have undefined index. How are you echoing it ? Can you do foreach($results as $r){echo $r['title_en'];} - v0d1ch
personally i'd use a define when a userlogs in define a lang define then you can put it in everywhere required without having to reference vars everywhere. slightly less overhead bit faster much easier to read and not get confused. - Dave

1 Answers

4
votes

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

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