Jump to content

Recommended Posts

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";
?>

Link to comment
https://forums.phpfreaks.com/topic/58215-sql-left-joins-and-order-by-error/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.