Jump to content

[SOLVED] Function not returning value, I'm not sure what is wrong.


Recommended Posts

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.

 

 

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.

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.

 

 

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.