Dubya008 Posted August 17, 2010 Share Posted August 17, 2010 I'm starting to use a class to perform DB functions because I think it is more efficient. I found this class on the internet and understand pretty well what is going on. My problem is that I can't put the results on the screen when I use the class. (I can do it with out using the class but I'd like to learn to use it) function fetch($info) { return mysql_fetch_array($info); this is how I'm attempting to use it $db = new mysql; $db->connect(); while($row = $db->fetch($db->query("SELECT * FROM Attributes"))) { echo $row['Attribute']."<br>"; } This just echos the first row forever and I'm not sure how else to go about this. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/210908-php-class-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 17, 2010 Share Posted August 17, 2010 That's because you are re-executing the query inside the while() statement. You would need to execute the query before the loop and only iterate over the result set in the while() statement. Link to comment https://forums.phpfreaks.com/topic/210908-php-class-question/#findComment-1100047 Share on other sites More sharing options...
Dubya008 Posted August 17, 2010 Author Share Posted August 17, 2010 Okay that makes sense... I tried this $db = new mysql; $db->connect(); $row = $db->fetch($db->query("SELECT * FROM Attributes")); while($row) { echo $row['Attribute']."<br>"; } and got the same thing. is there a do until statement in PHP? Link to comment https://forums.phpfreaks.com/topic/210908-php-class-question/#findComment-1100070 Share on other sites More sharing options...
Alex Posted August 17, 2010 Share Posted August 17, 2010 $db = new mysql; $db->connect(); $result = $db->query("SELECT * FROM Attributes"); while($row = $db->fetch($result)) { echo $row['Attribute']."<br>"; } Link to comment https://forums.phpfreaks.com/topic/210908-php-class-question/#findComment-1100071 Share on other sites More sharing options...
Dubya008 Posted August 17, 2010 Author Share Posted August 17, 2010 HA! I was almost there. That worked perfectly thanks so much everyone for the help. Link to comment https://forums.phpfreaks.com/topic/210908-php-class-question/#findComment-1100077 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.