title: sql query with left join in php don't work
body: <p>I made a SQL query in my database and it works perfectly, but when I try to put this same query into PHP, it doesn't work. I cannot figure out where is the error.</p>
  <pre><code>//connection variables
  $host = &quot;localhost&quot;;
  $database = &quot;kjnjkyeo3&quot;;
  $user = &quot;root&quot;;
  $pass = &quot;probajovo11&quot;;
  
  //connection to the database
  $connection = mysql_connect($host, $user, $pass, $database)
  or die ('cannot connect to the database: ' . mysql_error());
  
  
  $sql = &quot;SELECT ps_orders.id_order, ps_order_detail.id_order, ps_order_detail.product_reference AS Itemno,  ps_order_detail.product_quantity AS Saleqty, ROUND(ps_order_detail.total_price_tax_incl, 2) AS Cost, DATE_FORMAT(ps_orders.date_add , \'%Y%m%dT%T\' ) AS Dateoftrans\n&quot;
      . &quot;FROM ps_orders\n&quot;
      . &quot;LEFT JOIN kjnjkyeo3.ps_order_detail ON ps_orders.id_order = ps_order_detail.id_order&quot;;
  
  //loop to show all the tables and fields
  $loop = mysql_query($sql)
  or die ('cannot select tables');
  </code></pre>
  <p>I made a lot of changes in my query but I always get the message <code>cannot select tables</code>. When I make a simple query like <code>Select tables from $database</code>, it works fine.</p>
  <hr />
  <p>I made the changes:</p>
  <pre><code>//connection variables
  $host = &quot;localhost&quot;;
  $database = &quot;kjnjkyeo3&quot;;
  $user = &quot;root&quot;;
  $pass = &quot;probajovo11&quot;;
  
  //connection to the database
  $connection = mysql_connect($host, $user, $pass)
  or die ('cannot connect to the database: ' . mysql_error());
  
  //select the database
  mysql_select_db($database)
  or die ('cannot select database: ' . mysql_error());
  
  $sql = &quot;SELECT ps_orders.id_order, ps_order_detail.id_order, ps_order_detail.product_reference AS Itemno,  ps_order_detail.product_quantity AS Saleqty, ROUND(ps_order_detail.total_price_tax_incl, 2) AS Cost, DATE_FORMAT(ps_orders.date_add , \'%Y%m%dT%T\' ) AS Dateoftrans FROM ps_orders LEFT JOIN ps_order_detail ON ps_orders.id_order = ps_order_detail.id_order&quot;;
  
  //loop to show all the tables and fields
  $loop = mysql_query($sql)
  or die ('cannot select tables');
  </code></pre>
  <p>but it still doesn't work</p>