peacehunter Posted January 2, 2011 Share Posted January 2, 2011 I have a database which contains users data . Now I have made a class for fetching all data from database. But it brings only one data , not all. Although I have used while loop But it does not work.The code of my class is: <?phpclass own_status{ var $status; var $query; function __construct($id){ $this->query=mysql_query("SELECT * FROM status WHERE sender_id='$id'") or die(mysql_error()); while($row=mysql_fetch_array($this->query)){ $this->status=$row['status']; } } }?> And I made an instance on another page.Code: <?phprequire("class/reg_data.class.php");require_once("class/own_id.class.php");$cookie=$_COOKIE['user'];$data=new reg_data($cookie);$id=$data->id;$status_class=new own_status($id);$status=$status_class->status;echo $status;?> It fetches only one data not all, but dont know why. I am also facing this problem on making components in joomla and codeigniter framework. Plzzzzz give me a solution ......... Link to comment Share on other sites More sharing options...
boen_robot Posted January 2, 2011 Share Posted January 2, 2011 $this->status is still a single variable... no matter how much you're looping in the while, you're still assigning a single value to a single variable.Perhaps you want an array instead, like: class own_status { var $status = array(); var $query; function __construct($id){ $this->query = mysql_query("SELECT * FROM status WHERE sender_id='$id'") or die(mysql_error()); while($row = mysql_fetch_array($this->query)){ $this->status[] = $row['status']; } }} Link to comment Share on other sites More sharing options...
peacehunter Posted January 2, 2011 Author Share Posted January 2, 2011 $this->status is still a single variable... no matter how much you're looping in the while, you're still assigning a single value to a single variable.Perhaps you want an array instead, like:class own_status { var $status = array(); var $query; function __construct($id){ $this->query = mysql_query("SELECT * FROM status WHERE sender_id='$id'") or die(mysql_error()); while($row = mysql_fetch_array($this->query)){ $this->status[] = $row['status']; } }} Thnxxxxxxxxx for your help. The problem is solved . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.