zoobzen Posted June 18, 2010 Share Posted June 18, 2010 Hello, I am a real noob here and I am pulling my hair out over this problem .. I have a variable defined and I am only able to get a 1 or 0 value when calling it .. it is only one line, and interestingly, other just like it are working fine. Here is the line .. $this->mProdCat = (int)Catalog::GetCategoryByProduct($this->_mProductId); it is inside a function that is calling to the following .. // Retrieves category id from product id public static function GetCategoryByProduct($productId) { // Build SQL query $sql = 'CALL catalog_get_category_by_product(:product_id)'; // Build the parameters array $params = array (':product_id' => $productId); // Execute the query and return the results return DatabaseHandler::GetAll($sql, $params); } Finally, this is how I am using it .. $this->mProductSize = Catalog::GetProdsByCategory($this->mProdCat); Everything seems to be doing what it should except since I get this value of 1 (with varified data), I don't populate the list with the proper data .. This is probably easy for the experts, but me .. well ... Thanks for any help offered .. Quote Link to comment Share on other sites More sharing options...
priti Posted June 18, 2010 Share Posted June 18, 2010 Can you help us to know, Which one is causing issue $this->mProdCat = (int)Catalog::GetCategoryByProduct($this->_mProductId); // you say this is main issue OR $this->mProductSize = Catalog::GetProdsByCategory($this->mProdCat); //you say you are using this Both are different functions ? I got confused sorry. Secondly, In first function variable name is '$this->_mProductId' and in another '$this->mProdCat'. Please make sure it is not like this - '$this->_mProdCat'. Do let us know further to help you. Quote Link to comment Share on other sites More sharing options...
zoobzen Posted June 18, 2010 Author Share Posted June 18, 2010 This is the varibale that is giving the problem.. $this->mProdCat = (int)Catalog::GetCategoryByProduct($this->_mProductId); I am using the return of this as the variable input to the following .. $this->mProductSize = Catalog::GetProdsByCategory($this->mProdCat); I have read (and reread) my typing and verified my typing. and I am still only getting as return of the value 1 from this->ProdCat I am stumped.. Thanks for the interest .. Frank Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted June 18, 2010 Share Posted June 18, 2010 Remove the (int) from this line: $this->mProdCat = (int)Catalog::GetCategoryByProduct($this->_mProductId); Regardless of what Catalog::GetCategoryByProduct() returns, you're forcing it to convert to an int. If it returns nothing, it'll give a 0 otherwise it'll give a 1. However, the function looks like it'd return an array so you may need to do some extra processing to get the actual product category you want. Quote Link to comment Share on other sites More sharing options...
zoobzen Posted June 18, 2010 Author Share Posted June 18, 2010 I have tried casting the result as an int after this statement (becasue this->mProductSize requires an int) but same result. I am a real noob and I suspect that I may need additional processing since mProdCat is a variable (should only contain one number). I do not need to do anything with mProductSize though and it returns a much larger array. Any suggestions on how I may "process further"? I have tried giving mProductSize things like mProdCat[0] and mprodCat['category_id'] to no avail. Thanks .. Frank Quote Link to comment Share on other sites More sharing options...
zoobzen Posted June 18, 2010 Author Share Posted June 18, 2010 Something else interesting here, when I run the following code: $this->mProdCat = Catalog::GetCategoryByProduct($this->_mProductId); if (array_key_exists('category_id', $this->mProdCat)) $this->$mProdSelect = (int)$this->mProdCat['category_id']; else trigger_error('CategoryId not set'); $this->mProdCat reads back as the term Array in my browser .. when I run the query manually: SELECT category_id FROM product_category WHERE product_id = inProductId; I get the expected result under category_id Can anyone offer anything? Thanks .. Frank Quote Link to comment Share on other sites More sharing options...
zoobzen Posted June 18, 2010 Author Share Posted June 18, 2010 I solved my problem by using a table join and sub query in mySQL in order to eliminate the mProdCat variable that was giving me trouble. It is more efficient anyway, but I sure wonder what I was doing wrong with this .. Thanks anyway .. Frank Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted June 19, 2010 Share Posted June 19, 2010 Since I don't know the intracacies of your exact database handler I can't be sure but regardless of the actual SQL used, DatabaseHandler::GetAll($sql, $params); sounds like it should return more than one result (say you wanted all products in a category). In this case, any result given by the sql will probably use something like mysql_fetch_array (for MySQL databases) which returns an array to allow more than one row to be returned. With the code above, I expect you would have actually been looking for was $this->_mProdCat[0]['category_id'] (note the [0] because you want to access the first (only) row returned. 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.