babaz Posted November 1, 2010 Share Posted November 1, 2010 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 More sharing options...
BlueSkyIS Posted November 1, 2010 Share Posted November 1, 2010 those variables are undefined, "not set" in that function. Link to comment https://forums.phpfreaks.com/topic/217494-oo-programming/#findComment-1129207 Share on other sites More sharing options...
babaz Posted November 1, 2010 Author Share Posted November 1, 2010 but it does not cause any errors when it is used in AllProducts function. Link to comment https://forums.phpfreaks.com/topic/217494-oo-programming/#findComment-1129210 Share on other sites More sharing options...
BlueSkyIS Posted November 1, 2010 Share Posted November 1, 2010 because all variables are defined in the AllProducts function, for instance prodcode is defined thusly in AllProducts: $prodcode =array ($line['ProdCode']); Link to comment https://forums.phpfreaks.com/topic/217494-oo-programming/#findComment-1129213 Share on other sites More sharing options...
babaz Posted November 1, 2010 Author Share Posted November 1, 2010 thanks mate for correcting my silly mistakes...... cheers! it works fine now! Link to comment https://forums.phpfreaks.com/topic/217494-oo-programming/#findComment-1129220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.