No, $subcat is supplied as a string.
$ageId = $HTTP_GET_VARS["cboAge"];
$priceId = $HTTP_GET_VARS["cboPrix"];
$pieceId = $HTTP_GET_VARS["cboPiece"];
$awardWinner = $HTTP_GET_VARS["AW"]; //A True or False value
$newProduct = $HTTP_GET_VARS["New"]; //A True or False value
$SubCat = $HTTP_GET_VARS["SubCat"]; //Here SUBCAT IS
But all the others aren't objects either, they are also strings.
I'll supply more could below, and perhaps you guys can tell me where my problem is in my code:
/This function returns an array of products which matched the search criterion.(none,one,many)
$products = searchProducts($db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$pageIndex,$numToDisplay);
//This function returns the total number of products matching the search criterion.
$numFound = countProducts($db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat);
//This function returns a string of links which are used to navigate through the search results.
$navigation = searchNavigation($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$numFound,$numToDisplay,$pagesToDisplay,$pageIndex);
//Display, using the given templates, the given products, the navigation links and search count.
displayPage($prodTableTemp,$prodRowTemp,$prodTemp,$products,$numFound,$navigation,$pageIndex,$typeList,$imgDir,$txtKey );
This is all a PHP page that searches through the catalog, however I wanted to add Search by category functionality, and that is where $SubCat comes in. Am I adding it wrong? I followed the same convention as the other variables.
//This function counts the total number of products matchin the search criteria
function countProducts(&$db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat) {
$countQuery = countQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat);
$countQuery->doQuery2($db);
$row = $countQuery->getrow();
return $row["count"];
}
//Returns a string of links to navigate the search results.
function searchNavigation($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$numFound,$numToDisplay,$pagesToDisplay,$curPage){
$numPages = modCount($numFound,$numToDisplay); // determine, from the number of prods and prods/page, the number of pages of search results.
$numSets = modCount($numPages,$pagesToDisplay);//determine, from number of pages and pages/set, the number of sets of pages of search results.
$curSet = (int)($curPage/$pagesToDisplay); // the current set of pages being displayed.
if( $curPage % $pagesToDisplay == 0 ) { //A new set starts at 1, not 0.
$curSet = $curSet -1;
}
$nextSet = ""; //Image Link to first page of next set.
$prevSet = ""; //Image Link to first page of previous set.
$next = ""; //Image Link to next page of results.
$prev = ""; //Image Link to previous page of results.
$pages = ""; //String of text links to particular pages of results in the current set.
if( $curSet > 0 ) { //A previous set of pages exist
$page = ($pagesToDisplay * ($curSet-1)) + 1; //first page of previous set.
$image = "flecheg2.gif";
$prevSet = navImageLink($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$image,$page);
}
if( $curSet < ($numSets-1) ) { //A next set of pages exist
$page = (($curSet + 1 ) * $pagesToDisplay) + 1; //first page of next set.
$image = "fleched2.gif";
$nextSet = navImageLink($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$image,$page);
}
if( $curPage > 1 ) { //A previous page exists
$page = $curPage - 1;
$image = "flecheg1.gif";
$prev = navImageLink($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$image,$page);
}
if( $curPage < $numPages ) { //A next page exists
$page = $curPage + 1;
$image = "fleched1.gif";
$next = navImageLink($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$image,$page);
}
if ($numPages >= ($pagesToDisplay * ($curSet + 1)) ) { //Current set is at least full
$pagesInSet = $pagesToDisplay; //Display a full set of pages
} else { //Current set is not full
$pagesInSet = $numPages - ($curSet * $pagesToDisplay); // display remainder pages
}
$offset = $pagesToDisplay * $curSet;
// echo "curPage = $curPage pagesInSet = $pagesInSet numPages = $numPages, numSets = $numSets curSet = $curSet setOffset = $setOffset";
for( $i=1; $i<=$pagesInSet; $i++ ) { //loop throught the ages in the set.
$pages .= navLink($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$curPage,($i+$offset));
}
//Return the navigation links & images.
return $prevSet . $prev . $pages . $next . $nextSet;
}
function writeProduct(&$prod,&$template) {
//Get the individual data items of the product
list($prodId,$prodName,$prodAge,$prodPieces,$prodPrice,$prodSubCat,$prodSKU,$prodThmImg,$prodPopUpImg,
$awardProd,$newProd,$ageId,$skillId,$piecesId,$priceId) = $prod;
//Fill the product HTML template with the product data.
$template->set_var( array (
"PROD_ID"=>$prodId,
"PROD_NAME"=>$prodName,
"PROD_AGE"=>$prodAge,
"PROD_PIECES"=>$prodPieces,
"PROD_PRICE"=>$prodPrice,
"PROD_SKU"=>$prodSKU,
"PROD_IMAGE"=>$prodThmImg,
"PROD_AWARD"=>$awardProd,
"PROD_NEW"=>$newProd,
"PROD_SubCat"=>$SubCat,
"PROD_AGE_ID"=>$ageId,
"PROD_SKILL_ID"=>$skillId,
"PROD_PIECES_ID"=>$piecesId,
"PROD_PRICE_ID"=>$priceId ) );
//This function searches the product table for products matching the given criteria.
function searchProducts(&$db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$pageIndex,$numToDisplay) {
//Query the database for matching products
$prodQuery = productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$pageIndex);
$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 ); //Creates a product from the given data.
$products[$i++] = $prod; //put product into array.
}
return $products; //return the products found.
}
function createProduct(&$db,$prodRow) {
//data elements in the $prodRow
list($prodId,$newProd,$SubCat,$prodSubCat,$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 Category
$catQuery = catQuery($SubCat);
$catQuery->doquery2($db);
list($prodSubCat) = $SubCat->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,$SubCat,$ageId,$skillId,$piecesId,$priceId);
}
//Returns the query which searches the product table
function productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat,$pageIndex=1,$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.List_Group_Age_ID AS ageId,
prod.SubCat as SubCat
FROM
Produit prod,
Groupe_Age age
WHERE
".$whereClause."
ORDER BY
prod.Nom ASC
". $limit;
$q = new Query();
$q->setSQL($strSQL);
return $q;
}
function countQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat) {
$strSQL = "
SELECT COUNT(DISTINCT Produit_ID) AS count
FROM
Produit prod,
Groupe_Age age
WHERE " .constructWhereClause($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$SubCat);
$q = new Query();
$q->setSQL($strSQL);
return $q;
}