I am using PHP and MSSQL. (Latest Versions)
Basically, im pulling from the db a list of suppliers(Limo companies) that offer discounts(based on vehicle type). The result of the query is exactly what i'm asking for, although if a supplier is offering 3 discounts (1 discount for each of the vehicle types he owns) i get three rows (duh).. This causes me havok when using php/html to format the results because I dontwant to list the supplier 3 separate times.. i want tolist him once, but then indicate he has three vehicle types that are discounted.
Here is my query:
SELECT [clr].[dbo].[supplier].[supplierId]
,CAST([Company] AS varchar) AS [Company]
,CAST([HOCity] AS varchar) AS [HOCity]
,CAST([HOState] AS varchar) AS [HOState]
,CAST([HOPin] AS varchar) AS [HOPin]
,[Discount]
,CAST([CompanyDescription] AS varchar(max))AS [CompanyDescription]
,[startDate]
,[EndDate]
,[baseHrRate]
,[isPercentage]
,[DiscountHrRate]
,[geoImg]
,[clr].[dbo].[VehicleTypes].[VehicleTypeId]
,CAST([TypeName]AS varchar)AS [TypeName]
,[Capacity]
FROM [clr].[dbo].[supplier]
INNER JOIN [clr].[dbo].[supplierVehicles] ON
[clr].[dbo].[supplier].[supplierId] = [clr].[dbo].[supplierVehicles].[supplierId]
INNER JOIN [clr].[dbo].[supplierVehicleHourlyServiceRateDiscounts] ON
[clr].[dbo].[supplierVehicleHourlyServiceRateDiscounts].[supplierVehicleId] = [clr].[dbo].[supplierVehicles].[supplierVehicleId]
INNER JOIN [clr].[dbo].[VehicleTypes] ON
[clr].[dbo].[VehicleTypes].[VehicleTypeId]=[clr].[dbo].[supplierVehicles].[VehicleTypeId]
WHERE IsDeleted = 0 AND [HOCity] = '$cids'
AND CURRENT_TIMESTAMP < [EndDate] ORDER BY [Company] DESC, [TypeName] ASC
Here is my php/html to display results:
$suppliers = mssql_query($supplierQuery)
or die("You're Query is an Epic Failure". 'MSSQL error: ' . mssql_get_last_message());
while($supplier = mssql_fetch_array($suppliers)){
$company = $supplier['Company'];
$percentage = $supplier['Discount'];
$type = $supplier['TypeName'];
$img = $supplier['geoImg'];
$companyDesc = $supplier['CompanyDescription'];
echo "<div class=\"mini_deal_card\">";
echo "<div class=\"mini-card hotel 223203\">";
echo "<div class=\"right\">";
echo "<div class=\"redtag\">";
echo "<span class=\"price\">$59</span></div>";
echo "</div><div class=\"left\">";
echo " <a href=\"#\"><img src=\"/images/sm/" . $img . ".gif\" class=\"hotel-thumb\" alt=\"New York Limo Deals\"></a>";
echo "<p class=\"name\">" . $company . " </p>";
echo "<p class=\"hotel\">Save Up to " . $percentage . " % for your next " . $type . " Service</p>";
echo "<p></p>";
echo "<br class=\"clear-right\"> </div></div></div>";
}
Can anyone suggest a way to list the data better?