nikomou
01-09-2009, 12:44 AM
ok, I have 4 tables which I would like to join...
The first, deals:
DealsHandsetID DealsTariffID Price Monthsfree Monthshalf Cashback Gift RetailerID
2nd - handsets:
HandsetName Manufacturer HandsetID Date Features Description
3rd - tariffs:
TariffID TariffName TariffDescription Anytime OffPeak Texts LineRental Cost ContractType
4th - retailers:
RetailerID RetailerName RetailerImage RetailerCommission
My script below only using the handsets table.. but i would like to join the tables together to show only handsets with deals, and of those deals the ContractType must not equal "pp"
So, I want to do something like:
Select handsets.*, deals.*, tariffs.*, retailers.* from handsets LEFT JOIN deals ON handsets.HandsetID = deals.DealsHandsetID JOIN LEFT tariffs on tariffs.TariffID = deals.DealsTariffID LEFT JOIN retailers on retailers.RetailerID = deals.RetailerID WHERE tariffs.ContractType != 'pp' GROUP BY handsets.HandsetID
Heres my current code:
<?php
$conn = mysql_connect($address, $username, $password);
$rs = mysql_select_db($database, $conn);
$sql="SELECT * FROM handsets WHERE Date >= '803' GROUP BY HandsetName ORDER BY RAND() LIMIT 0, 40";
$rs = mysql_query($sql, $conn);
$j = 0;
while($row = mysql_fetch_array($rs)) {
$HandsetID = $row[HandsetID];
$Manufacturer = $row[Manufacturer];
$HandsetName = $row[HandsetName];
$Date = $row[Date];
$Features = $row[Features];
$Description = $row[Description];
$ManufacturerClean = str_replace(" ", "-", $Manufacturer);
$ManufacturerClean = strtolower($ManufacturerClean);
$HandsetNameShow = str_replace("$Manufacturer ", "$Manufacturer<br />", $HandsetName);
$HandsetNameClean = str_replace(" ", "-", $HandsetName);
$HandsetNameClean = strtolower($HandsetNameClean);
echo("
<div class=\"dealsmake\">
<strong>
<a class=\"menusmall\" href=\"/mobiles/$ManufacturerClean/$HandsetID.html\" title=\"$HandsetNameTitle\">
<img class=\"noborder\" alt=\"$HandsetNameTitle\" src=\"/med$HandsetID.jpg\" height=\"75\" />
<br /><br />$HandsetNameShow
</a>
</strong>
</div>
");
$j++;
if(($j % 4) == 0) echo("");
}
mysql_close();
?>
Please helppp!!! thanks!!!
The first, deals:
DealsHandsetID DealsTariffID Price Monthsfree Monthshalf Cashback Gift RetailerID
2nd - handsets:
HandsetName Manufacturer HandsetID Date Features Description
3rd - tariffs:
TariffID TariffName TariffDescription Anytime OffPeak Texts LineRental Cost ContractType
4th - retailers:
RetailerID RetailerName RetailerImage RetailerCommission
My script below only using the handsets table.. but i would like to join the tables together to show only handsets with deals, and of those deals the ContractType must not equal "pp"
So, I want to do something like:
Select handsets.*, deals.*, tariffs.*, retailers.* from handsets LEFT JOIN deals ON handsets.HandsetID = deals.DealsHandsetID JOIN LEFT tariffs on tariffs.TariffID = deals.DealsTariffID LEFT JOIN retailers on retailers.RetailerID = deals.RetailerID WHERE tariffs.ContractType != 'pp' GROUP BY handsets.HandsetID
Heres my current code:
<?php
$conn = mysql_connect($address, $username, $password);
$rs = mysql_select_db($database, $conn);
$sql="SELECT * FROM handsets WHERE Date >= '803' GROUP BY HandsetName ORDER BY RAND() LIMIT 0, 40";
$rs = mysql_query($sql, $conn);
$j = 0;
while($row = mysql_fetch_array($rs)) {
$HandsetID = $row[HandsetID];
$Manufacturer = $row[Manufacturer];
$HandsetName = $row[HandsetName];
$Date = $row[Date];
$Features = $row[Features];
$Description = $row[Description];
$ManufacturerClean = str_replace(" ", "-", $Manufacturer);
$ManufacturerClean = strtolower($ManufacturerClean);
$HandsetNameShow = str_replace("$Manufacturer ", "$Manufacturer<br />", $HandsetName);
$HandsetNameClean = str_replace(" ", "-", $HandsetName);
$HandsetNameClean = strtolower($HandsetNameClean);
echo("
<div class=\"dealsmake\">
<strong>
<a class=\"menusmall\" href=\"/mobiles/$ManufacturerClean/$HandsetID.html\" title=\"$HandsetNameTitle\">
<img class=\"noborder\" alt=\"$HandsetNameTitle\" src=\"/med$HandsetID.jpg\" height=\"75\" />
<br /><br />$HandsetNameShow
</a>
</strong>
</div>
");
$j++;
if(($j % 4) == 0) echo("");
}
mysql_close();
?>
Please helppp!!! thanks!!!