mysql - PHP OOP while loop -
i had problem looping data mysql using oop style.
so, here code:
class mysql { private $host; private $username; private $password; private $database; public $con; public function connect($sethost, $setusername, $setpassword, $setdatabase) { $this->host = $sethost; $this->username = $setusername; $this->password = $setpassword; $this->database = $setdatabase; $this->con = mysqli_connect($sethost, $setusername, $setpassword, $setdatabase); } public function query($setquery) { $query = mysqli_query($this->con, $setquery); return $query; } public function fetch($setfetch) { $fetch = mysqli_fetch_assoc($this->query($setfetch)); return $fetch; } } $objmysql = new mysql(); $con = $objmysql->connect("localhost" , "root" , "root" , "test"); while ($dataslideshow = $objmysql->fetch("select * slideshow)) { <h1><?php echo $dataslideshow['images']; ?></h1> }
the problem was, when refreshing page, excutes without limited in page, dont know why, but, in mysql table, contains 3 slideshow? so, computer got hang, , force close browsers. what's wrong code here?
by function definition , code be
$rs=$objmysql->query("select * slideshow"); while ($dataslideshow = $objmysql->fetch($rs)) { <h1><?php echo $dataslideshow['images']; ?></h1> }
and replace function definition
public function fetch($rs) { $row = mysqli_fetch_assoc($rs); return $row; }
Comments
Post a Comment