Fearpig Posted July 3, 2007 Share Posted July 3, 2007 Hi Guys, I'm having a few problems with a table I'm creating. The table is populated from an SQL database using two tables. I need to link the tables using a left join so that all of the products are visible and only relevant documents. So I created a view on the SQL server using a left join and this displays correctly however if I then try and sort the table using 'ORDER BY' it drops all records where there are not enteries on both tables. This occurs if I make the query in SQL or in PHP. Can anyone see where I am going wrong? Any help would be appreciated. <? $sql="SELECT * FROM qry_Domestic_Boilers_and_Docs ORDER BY 'Product'"; //this one doesn't work //$sql="SELECT * FROM qry_Domestic_Boilers_and_Docs"; //but this one works!! $result=odbc_exec($conn,$sql); if (!$result) {exit("Error in SQL");} echo "<table class='BodyText1' border=1>\n"; echo "<tr><th>Product</th><th>Type</th><th>Warranty</th><th>SEDBUK</th><th>kW</th></tr>"; while (odbc_fetch_row($result)) { $Product=odbc_result($result,"Product"); $Boiler_Type=odbc_result($result,"Type"); $Warranty=odbc_result($result,"Warranty"); $SEDBUK=odbc_result($result,"SEDBUK"); $Output_Power=odbc_result($result,"Power"); $Part_ID=odbc_result($result,"Part_ID"); echo "<tr><td><a href=\"Result_ByDomesticProduct.php?id=$Part_ID\">$Product</a></td><td align='middle'>$Boiler_Type</td><td align='middle'>$Warranty</td><td align='middle'>$SEDBUK</td><td align='middle'>$Output_Power</td></tr>"; } echo "</table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/58215-sql-left-joins-and-order-by-error/ 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.