papacostas Posted April 24, 2007 Share Posted April 24, 2007 I have an OOP problem. Im trying to create a simple DB class structure but when it lists the result it turns in to a never ending loop, what am i doing wrong? the getEvents function in Display calls the getEvents function in the DAO class which performs the SQL query by calling the executeSQL function that returns the resultset what should i change for this to work? thank you class Display { function getEvents() { include 'inc/dao.php'; $DAO=new DAO(); while ($events = $DAO->getEvents()) { echo $events['headline']; } } } class DAO { private $SQL; function executeSQL($SQL) { require_once 'inc/db.php'; $db = new DB(); $db->opendb(); $results= mysql_query($SQL); return mysql_fetch_array($results); } function getEvents () { $query = "select id, headline, startdate, desc_short, filename from events"; $query = $this->executeSQL($query); return $query; } } Quote Link to comment Share on other sites More sharing options...
linuxdream Posted April 24, 2007 Share Posted April 24, 2007 Looks like you are simply running the same query over and over since you want the result of mysql_fetch_array in the $events, not the the method getEvents(). That will simply keep running the same query and not iterate through the result like you want. You could simply assign mysql_fetch_array($results) to a class variable and call it in place of getEvents(). That way you will have a constant value there and not a new method/SQL query each iteration...which is what you need. Quote Link to comment Share on other sites More sharing options...
papacostas Posted April 25, 2007 Author Share Posted April 25, 2007 thank you very much, i created a fetchArray function in the DAO class that returns the mysql_fetch_array and it works perfectly now Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.