samedi 25 avril 2015

How do I add values to class objects then put them in an array?


I'm trying to embed queries into the variables in the class.
Like so:

    class FooBar{
        public $bar;
    }


    $result = array();

    $db = mysqli_connect("127.0.0.1", "foo", "foo", "Farm");
    $sql = "SELECT * FROM `Lot`;";
    $result = mysqli_query($db, $sql);

    while($row = mysqli_fetch_assoc($result)){
        $foo = new FooBar;            
        $foo->$bar = $row["cow"];

        array_push($result, $foo);
    }

But when I print the array using print_r($result), I'm just getting this as an output:

Array( )

I was hoping to see the objects stored in the array.

Where did I go wrong? What should I be doing?


Aucun commentaire:

Enregistrer un commentaire