Jump to content

Need help about fetching data from database with a class


peacehunter
 Share

Recommended Posts

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 .........

Edited by peacehunter
Link to comment
Share on other sites

$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

$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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...