Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

seventeen

macrumors member
Original poster
Apr 9, 2009
41
0
Denton, Tx
I am writing this comment class:

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:

Picture-2.png


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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.