0

No I'm doing wrong, I am modifying a system created by someone else but I can not show the information ... This is the code ...

$db = DB::getInstance();
$id = 1;
$query = $db->query("SELECT * FROM users WHERE id = ?", array($id));
$x = $query->results();
echo $x;

The error: Notice: Array to string conversion in...

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
GePraxa
  • 67
  • 1
  • 17

3 Answers3

0

use print_r($x) instead of echo $x echo is used to print string and numbers but could not print array, you may use var_dump too ... actually var_dump is used to print objects

Veshraj Joshi
  • 3,544
  • 3
  • 27
  • 45
0

Try using var_dump (instead of echo) if the return value is an object. For example:

var_dump($x);
shahzam
  • 321
  • 3
  • 5
  • In the table "users" there is a column "username" I want to list all user names ... – GePraxa Sep 21 '16 at 03:53
  • Update this for all users $db = DB::getInstance(); $id = 1; $query = $db->query("SELECT * FROM users"); $x = $query->results(); for ($i=0;$i"; } –  Sep 21 '16 at 04:27
0

use FOR :

$db = DB::getInstance();
$id = 1;
$query = $db->query("SELECT * FROM users WHERE id = ?", array($id));
$x = $query->results();

for ($i=0;$i<count($x); $i++){
        echo $x[$i]."<br/>";
    }
Dario
  • 417
  • 4
  • 17