mtlhd Posted May 27, 2009 Share Posted May 27, 2009 I'm fairly a noob so I need your expertise. I am trying to check if something in my database category _id is a certain value, and if it is, it is supposed to add some HTML to what it kicks out. It basically ignores everything I added. CODE: function Product($pid = 0){ if($pid){ $this->load($pid); } } function load($pid){ global $db; $this->pid = $pid; $pid = $db->escapeInt($pid); $q = $db->query('select products.*,image_id,image_desc from products,images where products.product_id=images.product_id and products.product_id = '.$pid.' and product_enabled = \'Y\' ORDER BY image_order'); $this->p = $q->getRow(); Debug::notice("get row: %s\n",$this->p); if(!$this->p){ //product not found or disabled throw new Exception('Product not found or disabled.'); } } function getID(){ return $this->p['product_id'];} function getSKU(){ return $this->p['product_sku'];} function getName(){ return $this->p['product_name'];} //function getDescription(){ return $this->p['product_desc'];} function getDescription(){ //Code added by ME for American Made Display if ($this->checkAmerican()){ $usa = "<img src='/images/american_made.gif' /><br />"; return $usa . $this->p['product_desc']; } else { return $this->p['product_desc']; //End code by ME } } //Code added by ME for American Made display function checkAmerican(){ global $db; $pid = $this->getID(); $sql = "SELECT category_id FROM product_category WHERE product_id=$pid"; $q = $db->query($sql); if($q == 185){ return TRUE; } } //End code by ME Those functions are then called later for display in an ARRAY. Why is the check American function failing? I don't get an error at all, just no response. Thanks in advance. Sorry if it is something simple and annoying. Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/ Share on other sites More sharing options...
Ken2k7 Posted May 27, 2009 Share Posted May 27, 2009 I don't know what your query method returns but try if ($q['category_id'] === 185) return true; Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-843609 Share on other sites More sharing options...
grissom Posted May 27, 2009 Share Posted May 27, 2009 Dunno if this will work, but off the top of my head, try putting some single quotes in your retrieval around the $pid so it looks like this : $sql = "SELECT category_id FROM product_category WHERE product_id = '$pid' "; Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-843638 Share on other sites More sharing options...
Mark Baker Posted May 28, 2009 Share Posted May 28, 2009 And consider adding a return false; if the condition isn't met rather than simply dropping out of the function Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-843920 Share on other sites More sharing options...
mtlhd Posted May 29, 2009 Author Share Posted May 29, 2009 Well im not sure why, i am looking into it, but when i changed the query function from $q = $db->query($sql); to $q = $db->quickQuery($sql); it worked fine. I ran those by php.net and they are not native to php5 so the guy before me wrote them or they came bundeled with the smarty platform. checking into it. will report back when I know for those who are interested. Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-845014 Share on other sites More sharing options...
Maq Posted May 29, 2009 Share Posted May 29, 2009 I don't even see where those 2 methods are defined. Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-845066 Share on other sites More sharing options...
mtlhd Posted June 1, 2009 Author Share Posted June 1, 2009 I don't even see where those 2 methods are defined. I finally found them, they are defined in the database class from elsewhere. they are called together by other pages within the site. Query defined: function Query($q,$rs_type = 'assoc'){ $this->rs_type = $rs_type; $this->query = $q; } QuickQuery defined: function quickQuery($sql, $doreturn = true){ $q=$this->query($sql); if($doreturn){ return $q->getOne(); } } Thanks for all your help everyone. Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-846959 Share on other sites More sharing options...
Maq Posted June 1, 2009 Share Posted June 1, 2009 Did you actually resolve this issue? I see you marked it solved, but sounds otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/159921-solved-function-not-returning-value-im-not-sure-what-is-wrong/#findComment-846963 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.