Hi everyone,
I have an online catalog on my extranet, running on php and mysql. I want to be able to search by price, but price range.
If I have links like: 10$-15$
15$-23$
etc....
See the problem is that I don't have any suggested retail prices, just price ranges, so I stored min and max prices in two separate INT fields. So i could use simple comparison operators like: WHERE min_price >= 5 AND max_price <= 15
Here is my code:
I pass a min and max variable through the url and do a $_GET.
then
$strSQLPrice = mysql_query("Select Price_Range_ID FROM Price_Range WHERE min_price >= $min AND max_price <= $max");
$whereClause = constructWhereClause($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$subCat, $min, $max);
$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.vr AS vr,
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,
prod.prio AS priority
FROM
Produit AS prod,
Groupe_Age AS age
WHERE
".$whereClause."
ORDER BY prod.priority ASC
". $limit;
$q = new Query();
$q->setSQL($strSQL);
return $q;
function constructWhereClause($ageId,$priceId,$pieceId,$awardWinner,$newProduct,$subCat, $min, $max) {
$i = 0; //Count the number of clauses
$whereStmts = array();//an array to hold each clause
$rows = mysql_num_rows($strSQLPrice);
for ($i=0; $i < $rows; $i++){
list($id,$numOrder) = pg_fetch_row($strSQLPrice,$i);
$whereStmts[$i++] = " prod.Price_Range_id = $id ";
}
$numClauses = $i;
$whereClause = "";
for( $j = 0; $j <$numClauses - 1; $j ++ ) { // loop through each clause, construct proper SQL
$whereClause .= $whereStmts[$j]. " AND ";
}
$whereClause .= $whereStmts[$numClauses-1];
return $whereClause;
}
Would anyone know what the problem with my code is?
It doesn't seem to be working properly, and the Where clause doesn't seem to take effect.
What is being outputted by the browser is everything... It displays everything as if there were no WHERE clause, like a basic Select *.
I would apreciate any help.
MK
thx