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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.