Page 1 of 1

for each issue

Posted: Fri Sep 15, 2006 5:31 pm
by KSquared
Hi All,

I have a simple class:

Code: Select all

class DbQuery{ 
    var $selectWhat; 
	var $table;
	var $where;
	var $queryString;
	var $row;
	
	function buildQuery($selectWhat, $table, $where)
	{
		// check if a WHERE statement is needed
		if($where){
			$this->where = $where;
			return $this->where;
		}
		
		$this->queryString = "SELECT ".$selectWhat." FROM ".$table;
		
		$return = mysql_query($this->queryString) or die("Could not connect to MySQL database from buildQuery" .mysql_error());
		$this->row = mysql_fetch_array($return);
		
	}
     
}
Im simply wanting to loop through the results as follows:

Code: Select all

include('includes/classes/DbQuery.php');
$dbquery = &New DbQuery; 
$dbquery->buildQuery("*", "events", false);
					
foreach ($dbquery->row as $value) {
						
	echo "$value<br />\n";
}
I only have one row in the db, however it seems to loop and repeat the same info twice... cant figure out why...

link if needed: http://www.beyondblueinteriors.com/v2/specials.php

Thanks
Any help would be great,

Posted: Fri Sep 15, 2006 5:37 pm
by feyd
hint: mysql_fetch_array() explains it.

var_dump($dbquery->row) may be of interest too.

Posted: Fri Sep 15, 2006 6:14 pm
by KSquared
Thanks much!

A bit of rearranging and its working now.