Hi i am using foreach in php oops to output data from the mysqlbut each data outputs twice please check my code and help it i have tried but no correct result
Here is the code below i have used
class getdata extends db{ public function getdata(){ $sql = "SELECT * FROM users"; $results = $this->connect()->query($sql); $numrows = $results->num_rows; if($numrows > 0){ while($row = $results->fetch_assoc()){ $data[] = $row; } return $data; } else{ echo 'no values'; } } } class showusers extends getdata{ //show users public function showusers(){ $datas = $this->getdata(); foreach($datas as $data){ echo $data['id'].'<br>'; echo $data['name'].'<br>'; } } } $showusers = new showusers(); $showusers->showusers();
var_dump(count($datas));give you the expected amount of records, or is that number double of what you’d expect already?