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:
//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:
//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
//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.
For AgeID, a value is in a ageID table, and then that table relates to a value in the products table.
I don't know how to takle this, i've tried and tried.
Any help would be greatly apreciated.