for each issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KSquared
Forum Commoner
Posts: 25
Joined: Tue Aug 29, 2006 4:07 pm

for each issue

Post 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,
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hint: mysql_fetch_array() explains it.

var_dump($dbquery->row) may be of interest too.
KSquared
Forum Commoner
Posts: 25
Joined: Tue Aug 29, 2006 4:07 pm

Post by KSquared »

Thanks much!

A bit of rearranging and its working now.
Post Reply