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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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']); Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.