Here is my query:
if($GetSize != ""){
$r = mysql_query("select * from `ProductSizes` ps, `products` p WHERE `ps.Size`='$GetSize' and `p.id`=`ps.Product`");
} else {
$r = mysql_query("SELECT * FROM `products` WHERE `Category`='$Cat' $FilterSQL $FilterSQLS $BrandSearch ORDER $OrderBy LIMIT $first_product_shown1, $products_per_page");
}
while($rowi = mysql_fetch_array($r))
{
$id = $rowi['id'];
$Title = $rowi['Title'];
$Image = $rowi['Image'];
$Price = $rowi['Price'];
$PriceOld = $rowi['PriceOld'];
$Rating = $rowi['Rating'];
$SDProductCode = $rowi['ProductCode'];
$Lev = $Price * GetSetting('PoundRate');
$LevOld = $PriceOld * GetSetting('PoundRate');
$Lev = number_format($Lev, 2, '.', '');
$LevOld = number_format($LevOld, 2, '.', '');
}
I think i have some mistake in it because i get no results.
Do you find any mistake and how the fixed variant must look like ?
Thanks in advance!
You are using WHERE
clause before JOIN
:
Correction:
mysql_query("
select * from `ProductSizes` c
join `products` o on o.`id` = c.`Product`
WHERE `c.Size` = '$GetSize'
");
Side Note:
I suggest you to use mysqli_*
or PDO
instead of mysql_*
becuase it's deprecated and not available in PHP 7.
Consider modifying your query like below cause your query syntax is wrong. JOIN
clause should come before WHERE
select c.*
from `ProductSizes` c
join `products` o on o.`id` = c.`Product`
WHERE c.`Size` = '$GetSize';
SQL query seems to be incorrect... try this
mysql_query("select * from `ProductSizes` ps, `products` p WHERE `ps.Size`='$GetSize' and p.`id`=ps.`Product`")
Also a good idea to check MySQL query result using mysql_query_error function
if(mysql_query_error()) {
//Probably syntax error
}
Try this
mysql_query("select * from `ProductSizes` c join `products` o on o.`id`=c.`Product` WHERE c.`Size`='$GetSize'")