Jump to content

OO programming


babaz

Recommended Posts

hello,

 

im trying to read the database and store values into an array list. when i run the script it says undefined variable prodcode, name, price in the function  prod details. any help pliz.

appreciate the help.

 

thnaks!

 


require("dbfunctions.inc.php");
$count;


class Product
{
// The following are the attributes of the Product class, that is,

var $prodcode = array();
var $name = array();
var $price = array();
/* 	CONSTRUCTOR
	Every class has at least one constructor method. We create an instance of a class
	using the class's constructor
*/

function AllProducts()
{
	$qry = "Select ProdCode, Name, Price, Image from products";

//execute query
$products = execute_query($qry);


if (!$products)
{die('query failed.');
}
	$i = 0;
	global $count;  
	$count= mysql_num_rows($products);
	while ($line = mysql_fetch_array($products, MYSQL_ASSOC)) 
{ 
	$prodcode =array ($line['ProdCode']);
	//$name[$i] = $line['Name'];
	//$desc[$i] = $line['Desc'];
	//$price[$i] = $line['Price'];
	//$category[$i] = $line['Category'];
	$i++;

}



}




// Method to print the Shopping Cart details to the screen
function ProdDetails()
{
	global $count;
	echo $count;
	echo $count;
	for ($i = 0; $i <= $count; $i++)
{
	//echo "<tr><td>";
	echo "<br>Product Code: <a href=DisplayProduct.php?prodcode=" . $prodcode[$i].
		">" .$prodcode[$i]. "</a>"."<br>";
	echo  "Product Name: ".$name[$i]." <br>". "Price: FJD$ " .$price[$i]."<br>"; 
         

} 
}

// Method to print the Shopping Cart details to the screen
function getProdCode()
{

	echo "Product Code: " . $this->prodcode . "<br>"; 

} 



} // END OF CLASS







Link to comment
https://forums.phpfreaks.com/topic/217494-oo-programming/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.