physx Posted April 9, 2010 Share Posted April 9, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/198174-format-mssql-output/ Share on other sites More sharing options...
roopurt18 Posted April 9, 2010 Share Posted April 9, 2010 In your PHP loop you just keep a variable $current_supplier. At the beginning of the loop, if the row's supplier is not equal to the value in $current_supplier, display the supplier. At the end of the loop, be sure to set the variable $current_supplier equal to the value in the row. Quote Link to comment https://forums.phpfreaks.com/topic/198174-format-mssql-output/#findComment-1039800 Share on other sites More sharing options...
Gamic Posted April 9, 2010 Share Posted April 9, 2010 I would look at adding something like the below to your output (commented out lines). This will only not display the company name if the current company being echoed is the same as the last. <?php echo " <a href=\"#\"><img src=\"/images/sm/" . $img . ".gif\" class=\"hotel-thumb\" alt=\"New York Limo Deals\"></a>"; //if ($lastCompany != $company) 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>"; //$lastCompany = $company; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198174-format-mssql-output/#findComment-1039807 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.