Hi all
I've reached an impasse, dunno if impasse has an e, is it impass?
Anyhow, I have a page that displays products, problem is that each row contains only two products, and I want to have 3 on each <tr.
There is a file called productrow.tpl that my search.php calls.
This is what productrow.tpl contains:
<tr align=center>
{PRODUCT}
</tr>
That's all. If I change the code to this:
<tr align=center>
{PRODUCT}
{PRODUCT}
</tr>
Then each there are duplicates. Instead of 2 items per row, there are 4. But, the two extra items are the same as the previous two. So it's <td>item1</td><td>item2></td><td>item1></td><td>item2</td>
Which obviously is not what I want. So i'm assuming that this means that {PRODUCT} contains a resultset of two queried items, and two only, so I have to put 3 in {PRODUCT} instead of 2. But i'm not able to find out how, here is the search.php code that uses {PRODUCT}.
Any help you can provide as to how I could put 3 items in one row will be extremely appreciated.
here's search.php.
/
The products found are parsed into the following HTML template files.
/
$prodTableTemp = "templates/ptemp.tpl"; //The general HTML for the page. (header and footer).
$prodRowTemp = "templates/productRow.tpl"; //the HTML for a row of poducts
$prodTemp = "templates/product.tpl"; // the HTML for a single product
/
These are the variables passed by the get request
/
$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
$pageIndex = isset($HTTP_GET_VARS["iPage"]) ? $HTTP_GET_VARS["iPage"] : 1; //The page of the results to dislay. If not defined, display 1st page.
$txtKey = $HTTP_GET_VARS["txtKey"]; //Not sure what this is for.
/
These variables, passed by the get request, are a bit more complicated and therefore more difficult to create valid search criterion. These variables are, therefore, not used in this current implementation. They are declared for future development.
/
$typeList = $HTTP_GET_VARS["cboType"]; //comma separated list of type ids.
$skillList = $HTTP_GET_VARS["cboSkill"]; //comma separated list of skill ids.
$imgDir = $uppathImg;
$numToDisplay = $NB_ELEM_AFFICHER;
$pagesToDisplay = 10;
//This function returns an array of products which matched the search criterion.(none,one,many)
$products = searchProducts($db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex,$numToDisplay);
//This function returns the total number of products matching the search criterion.
$numFound = countProducts($db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct);
//This function returns a string of links which are used to navigate through the search results.
$navigation = searchNavigation($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$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 );
/ End of Script /
/*
Functions
*/
//This function displays the products page
function displayPage($prodTableTpl,$prodRowTpl,$prodTpl,&$products,$numFound,$navigation,$pageIndex,$typeId,$imgDir, $txtKey ) {
//Create a Template to parse the HTML template files.
$template = new Template();
//Set the Product Table HTML Template
$template->set_file($prodTableTpl,$prodTableTpl);
//Write Search Count
$template->set_var("NUM_PRODS_FOUND",$numFound);
//Write Search Navigation links
$template->set_var("PROD_SEARCH_PAGES",$navigation);
//Write the products.
writeProducts($template,$prodRowTpl,$prodTpl,$products);
$template->set_var(array (
"IMAGE_DIR"=>$imgDir,
"PAGE_INDEX"=>$pageIndex,
"PROD_TYPE_ID"=>$typeId,
"PROD_KEY"=>$txtKey ) );
$template->pparse("display",$prodTableTpl);//out put the parsed html
}
//This function counts the total number of products matchin the search criteria
function countProducts(&$db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct) {
$countQuery = countQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct);
$countQuery->doQuery2($db);
$row = $countQuery->getrow();
return $row["count"];
}
// 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,$curPage,($i+$offset));
}
//Return the navigation links & images.
return $prevSet . $prev . $pages . $next . $nextSet;
}
//This function displays the products found in a 2X2 table.
function writeProducts(&$template,$prodRowTpl,$prodTpl,&$products) {
//Count the number of products found.
$count = is_array($products) ? count($products) : 0;
//Set the Product Row and Product HTML templates.
$template->set_file($prodRowTpl,$prodRowTpl);
$template->set_file($prodTpl,$prodTpl);
if( !$count ) { //If there are no products to display, display "no products message" and return.
$noProductsHTML = "<tr><td align=center height=100 width=130>No product found for this criteria.</td></tr>";
$template->set_var("PROD_ROWS",$noProductsHTML);
return;
} //Otherwise, there exists at least one product to display...
//Determine if there are an even number of products
if( $count % 2 == 0 ) {
$odd = false;
$c = ($count)/2;
} else {
$odd = true;
$c = ($count-1)/2;
}
$i = 0;
for( $i; $i<$c; $i++ ) { //write an even number of products
writeTwoProducts($products,$i*2,$prodTpl,$template);
$template->parse("PROD_ROWS",$prodRowTpl,true);
}
if( $odd ) { //write the remaining product if there was an odd number of products.
writeOneProduct($products,$i*2,$prodTpl,$template);
$template->parse("PROD_ROWS",$prodRowTpl,true);
}
}
//Write two products in the template
function writeTwoProducts(&$products,$i,$prodTpl,&$template) {
$p = $products[$i];
writeProduct($p,$template);
$template->parse("PRODUCT",$prodTpl);
$p = $products[++$i];
writeProduct($p,$template);
$template->parse("PRODUCT",$prodTpl,true);
}
//Write only one product
function writeOneProduct(&$products,$i,$prodTpl,&$template) {
$p = $products[$i];
writeProduct($p,$template);
$template->parse("PRODUCT",$prodTpl);
}
//Writes the product to the template
function writeProduct(&$prod,&$template) {
//Get the individual data items of the product
list($prodId,$prodName,$prodAge,$prodPieces,$prodPrice,$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_AGE_ID"=>$ageId,
"PROD_SKILL_ID"=>$skillId,
"PROD_PIECES_ID"=>$piecesId,
"PROD_PRICE_ID"=>$priceId ) );
writePopUpImg($prodId,$prodPopUpImg,$template); //write HTML to template for pop up image of template
writeNewText($newProd,$template);//write HTML to template to display "New" text for the product
}
//This function searches the product table for products matching the given criteria.
function searchProducts(&$db,$ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex,$numToDisplay) {
//Query the database for matching products
$prodQuery = productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$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.
}
//Returns the query which searches the product table
function productQuery($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$pageIndex=1,$numToDisplay=4) {
$offset = ($pageIndex-1)*$numToDisplay;
$limit = " LIMIT $offset,$numToDisplay ";
$whereClause = constructWhereClause($ageId,$priceId,$pieceId,$awardWinner,$newProduct);
$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
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) {
$strSQL = "
SELECT COUNT(DISTINCT Produit_ID) AS count
FROM
Produit prod,
Groupe_Age age
WHERE " .constructWhereClause($ageId,$priceId,$pieceId,$awardWinner,$newProduct);
$q = new Query();
$q->setSQL($strSQL);
return $q;
}
?>
There may be some } missing, but that's ok, I had to shorten the code due to allowable max text lenght for posts. But the code I took out seemed irrelevant.
Thanks