troubleshooting Question

Can't loop through simple DB object in PHP

Avatar of EMB01
EMB01Flag for United States of America asked on
PHPMySQL Server
10 Comments1 Solution295 ViewsLast Modified:
The variable $db->numRows(); outputs 428 but when I go to loop through, it doesn't give me any outut.  I've tried several different ways to loop through.  

// get database model
require_once('models/database.php');
$db = new database();

$db->query("
SELECT ItemName, ItemSKU, ItemCondition
from items where itemname not in

(SELECT itemname
FROM items
GROUP BY itemname
HAVING ( COUNT(itemname) = 1 )
)
");

echo $db->numRows();

//print_r($db->obj);die;

while($db->obj)
{
	$db->obj->ItemName;
}

Here's the database methods:

function query($sql)
	{
	
		// Perform Query
		$this->result = mysql_query($sql);

		// Check result
		// This shows the actual query sent to MySQL, and the error. Useful for debugging.
		if (!$this->result)
		{
		
			die(mysql_error());
			
		}
		else
		{
		
			$this->obj = mysql_fetch_object($this->result);
		
		}
	
	}
	
	function numRows()
	{
	
		if (!is_null($this->result))
		{
		
			return mysql_num_rows($this->result);
		
		}
	
	}
ASKER CERTIFIED SOLUTION
Scott Madeira

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros