I have faced a problem in returning a multiple values from the database in an array because every time i run this code it returns only the first row from the database but not all the rows and here is my code:
In classes.php:
class user{
public function showwinners(){
$query="SELECT points,memberid,uname FROM user ";
$all_answers=array();
if($query_run=mysql_query($query)){
if(mysql_num_rows($query_run)==NULL){
return 0;
}
while($query_row=mysql_fetch_assoc($query_run)){
$one=$query_row['points'];
$two=$query_row['memberid'];
$three=$query_row['uname'];
if($one>=1){
$first=$one;
$second=$three;
array_push($all_answers,['name'=>$second,'points'=>$first]);
return $all_answers;
}
}
}
}
}
and in showwinners.php:
$userobj=new user();
$arr=array();
$arr=$userobj->showwinners();
foreach ($arr as $key => $a) {
if(isset($a['name']))
echo $a['name'];
if(isset($a['points']))
echo $a['points'];
}