Parameter passing problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Klaws_wolverine
Forum Commoner
Posts: 32
Joined: Mon Sep 29, 2003 10:11 am

Parameter passing problem.

Post by Klaws_wolverine »

Hello all,

I have a BIG problem, and I would apreciate any help anyone can provide. I have a variable value problem, I don't know why but I think the wrong value is being passed to the wrong variable.

This is for our extranet catalog, we have clothing products geared towards kids, and for each product i'm not displaying the right Age Group applicable for this particular clothing SKU.

Here is the relevant code:

Code: Select all

//This function searches the product table for products matching the given criteria.
function searchProducts(&$db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex,$Catnum,$numToDisplay) {

	//Query the database for matching products
	$prodQuery = productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex,$Catnum);
	$prodQuery->doquery2($db);
	$i=0;
	$products = array();
        while( $p = $prodQuery->getrow() ) {//Loop through the rows in the product table which matched the criteria.
		$prod = createProduct($db, $p, $subCat ); //Creates a product from the given data.
		$productsї$i++] = $prod; //put product into array.

	}
   
	return $products; //return the products found.
}
Now, in the below code, when I manually specify an ageID, like $ageId=14; for example it displays it only when I specify it in the below function:

Code: Select all

//Gets product information from other tables and returns a Product.
function createProduct(&$db,$prodRow) {

	//data elements in the $prodRow
	list($prodId,$newProd,$awardProd,$prodName,$prodThmImg,$prodPopUpImg,$prodSKU,$piecesId,$priceId,$ageId) = $prodRow;

	//get the pieces
	$pieceQuery = piecesQuery($piecesId);
	$pieceQuery->doquery2($db);
	list($prodPieces) = $pieceQuery->getrow();

	//get the price
	$priceQuery = priceQuery($priceId);
	$priceQuery->doquery2($db);
	list($prodPrice) = $priceQuery->getrow();

	//get the age
	$ageQuery = ageQuery($ageId);
	$ageQuery->doquery2($db);
	list($prodAge) = $ageQuery->getrow();

	//return the Product
	return array(	$prodId,$prodName,$prodAge,$prodPieces,$prodPrice,$prodSKU,$prodThmImg,$prodPopUpImg,
					$awardProd,$newProd,$ageId,$skillId,$piecesId,$priceId);
}
Here is the AgeQuery

Code: Select all

//Returns the query which gets the age name from the ages table
function ageQuery($ageId) {

	$strSQL =
	"SELECT
		age.Nom AS prodAge
	FROM
		tableName age
	WHERE
		age.Age_Id='$ageId'";

        $q = new Query();
        $q->setSQL($strSQL);
        return $q;

}
From the code I posted above, would anyone know what is going on with my Age Query or why the wrong value is being passed?
For some reason, it seems that the value of $Catnum is being passed to $ageID.

Any help would be greatly apreciated.
Thx
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$prod = createProduct($db, $p, $subCat ); //Creates a product from the given data.
where's this $subCat (array?) coming from?
Klaws_wolverine
Forum Commoner
Posts: 32
Joined: Mon Sep 29, 2003 10:11 am

subCat

Post by Klaws_wolverine »

Hi,

$subCat is from the queryString, I didn't post the http_get_vars code.
$subCat is $Catnum.

For AgeID, an ID value is in the age column in the products table, this ID relates to an actual age in the age table.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

uh? Then how's this supposed to work?

Code: Select all

$prod = createProduct($db, $p, $subCat ); //Creates a product from the given data. 
[...]
function createProduct(&$db,$prodRow) {
   //data elements in the $prodRow
   list($prodId,$newProd,$awardProd,$prodName,$prodThmImg,$prodPopUpImg,$prodSKU,$piecesId,$priceId,$ageId) = $prodRow;
[...]
edit: ah sorry, I missed that you're calling the function with more parameters than it handles....
Klaws_wolverine
Forum Commoner
Posts: 32
Joined: Mon Sep 29, 2003 10:11 am

mistake

Post by Klaws_wolverine »

Hi,

Yes sorry about that, the number of parameters in the function and function call are identical, I had forgotten to include that in the function.

But it is in fact there, so that's not the problem, sorry about that.

Code: Select all

$prodQuery = productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex,$subCat);

Code: Select all

//Returns the query which searches the product table
function productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex=1,$subCat,$numToDisplay=6) {
         
	$offset = ($pageIndex-1)*$numToDisplay;
	$limit = " LIMIT $offset,$numToDisplay "; 
	$whereClause = constructWhereClause($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$subCat);
	$strSQL =
	"SELECT DISTINCT 
		prod.Produit_ID AS prodId,
		prod.Is_New AS newProduct,
		prod.Is_Award_Winner AS awardProd,
		prod.Nom AS prodName,
		prod.img_thumb_1 AS prodThmImg,
		prod.img_pop_1 AS prodPopUpImg,
		prod.SKU AS prodSKU,
		prod.Number_Piece_Range_ID AS piecesId,
		prod.Price_Range_id AS priceId,
		prod.subCat AS subCat,
		prod.List_Group_Age_ID AS ageId,
		prod.prio AS priority

	FROM
		tableName AS prod,
		ageTable AS age

	WHERE
	".$whereClause." 
	ORDER BY prod.priority ASC
	". $limit;
	$q = new Query();
	$q->setSQL($strSQL);
	return $q;
}
I don't think there's much else relevant code to post.
I still can't figure it out.

Hopefully someone will spot it as i'm nearing deadline time.

Thx
Klaws_wolverine
Forum Commoner
Posts: 32
Joined: Mon Sep 29, 2003 10:11 am

ne1

Post by Klaws_wolverine »

Anyone??
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

try adding some echos.

start at the top. echo out all the parameters used. then repeat that every time something gets set. give it this forumula:

Code: Select all

echo "<br>what's going on: parameter list";
"what's going on" is what your doing at that line; ":" seperats so you know you're aboutto look at the parameter list; the parameter list is merely what all the parameters on, use a delimiter between them ofyour choice so you'll know if something's not set. use the same line with "what's goingon" changing to be relevant. that way you always have the same data in the same order. then find out where the age setting is going wrong. find the begining of that set of instruction, find the end. show us everything in between, but use the php tags instead of the code tags (nicer to look at)

right now i don't see it actually being set. until iknow where the issue is that it gets changed, i can't tell you anything, others may be in the same boat
Post Reply