I am writing this comment class:
Here is what the query inside the constructor will return when run in the database:
But when I run it, this is what print_r(new Comment(1)); spits out:
Any ideas why I'm only getting the first character of each field?
Thanks.
Code:
class Comment {
public $id;
public $post_id;
public $name;
public $email;
public $website;
public $body;
public $date;
public $ip_address;
public $status;
function __construct($id) {
global $db;
$resc = $db->query("SELECT * FROM blog_comments WHERE id='$id' LIMIT 1");
while($row = $db->fetch_assoc($resc)) {
while ($comment = current($row)) {
$key = key($row);
$this->$key = $comment{$key};
next($row);
}
}
}
}
Here is what the query inside the constructor will return when run in the database:

But when I run it, this is what print_r(new Comment(1)); spits out:
Code:
Comment Object
(
[id] => 1
[post_id] => 1
[name] => J
[email] => j
[website] => h
[body] => b
[date] => 1
[ip_address] => :
[status] => 1
)
Any ideas why I'm only getting the first character of each field?
Thanks.