I have a PHP class:
<?php
//connectionclass.php
class connectionclass{
public $conn;
public $warn;
public $err;
function __construct(){
$this->connect();
}
private function connect(){
$this->conn = @ new mysqli('localhost', 'sever_user', 'user_password');
if ($this->conn->connect_error) {
$this->conn = FALSE;
$this->warn = '<br />Failed to connect database! Please try again later';
}
}
public function get_data($qry){
$result = $this->conn->query($qry);
if ($result->num_rows>=1) {
while($row=$result->fetch_assoc()){
$rows[] = $row;
}
return $rows;
} else {
$this->err = $this->conn->error;
return FALSE;
}
}
}
?>
and a PHP page:
<?php
//login.php
include('/include/connectionclass.php');
$db = new connectionclass();
$query = "SELECT * FROM USERS WHERE user_country='India'";
$data = $db->get_data($query);
$rownum = count($data);
for($i=0;$i<$rownum;$i++){
echo $data[$i]['name'].'- '.$data[$i]['age'].'<br />';
}
?>
Is there any idea for an easier way to iterate $data
in the PHP page?