title: Is this query non compatible with php? It there a glaringly obvious syntax error because I can't get it to run
body: <p>So, I am currently making a dashboard for my boss, displaying data from a logistics perspective, he has sent me his own MS Access query, for the life of my I cannot make it run, in an attempt to make a table our worker can view from the data it should be pulling. Is anything glaringly wrong with it?</p>
  
  <p>I'm just an apprentice, but my seniors have suggested that everything with ORDER requires [] around it to run through PHP and codeigniter, I have tried altering the syntax through a validator, yet i seem to have hit a brick wall. Below is the original. </p>
  
  <pre><code>function order_table()
      {   
          $date = date("Y-m-d");
          $macsdb = $this-&gt;load-&gt;database('macs', TRUE);
  
  $query = $macsdb-&gt;query("SELECT temp123.Hour, temp123.User, Count(temp123.[ORDER]) AS CountOfORDER, Sum(temp123.SumOfCountOfPRODUCT) AS SumOfSumOfCountOfPRODUCT, Sum(temp123.SumOfSumOfQUANTITY) AS SumOfSumOfSumOfQUANTITY
  FROM (SELECT temp456.Hour, temp456.User, temp456.[ORDER], Sum(temp456.CountOfPRODUCT) AS SumOfCountOfPRODUCT, Sum(temp456.SumOfQUANTITY) AS SumOfSumOfQUANTITY
  FROM (SELECT WHAUDIT.Date, Format([Time],'hh') AS [Hour], WHAUDIT.User, WHAUDIT.[ORDER], Count(WHAUDIT.PRODUCT) AS CountOfPRODUCT, Sum(WHAUDIT.QUANTITY) AS SumOfQUANTITY
  FROM WHAUDIT
  WHERE (((WHAUDIT.type)='I11' Or (WHAUDIT.type)=' 11'))
  GROUP BY WHAUDIT.Date, Format([Time],'hh'), WHAUDIT.User, WHAUDIT.[ORDER]
  HAVING (((WHAUDIT.Date)='$date')) as temp456
  GROUP BY temp456.Hour, temp456.User, temp456.[ORDER]) as temp123
  GROUP BY temp123.Hour, temp123.User
  ORDER BY temp123.Hour DESC;");
  
       return $query-&gt;result();
          $macsdb-&gt;close();        
      }
  </code></pre>
  
  <p>The query by itself is as follows:</p>
  
  <pre><code>SELECT
    temp123.Hour,
    temp123.User,
    Count(temp123.[ORDER]) AS CountOfORDER,
    Sum(temp123.SumOfCountOfPRODUCT) AS SumOfSumOfCountOfPRODUCT,
    Sum(temp123.SumOfSumOfQUANTITY) AS SumOfSumOfSumOfQUANTITY
  FROM
    (
      SELECT
        temp456.Hour,
        temp456.User,
        temp456.[ORDER],
        Sum(temp456.CountOfPRODUCT) AS SumOfCountOfPRODUCT,
        Sum(temp456.SumOfQUANTITY) AS SumOfSumOfQUANTITY
      FROM
        (
          SELECT
            WHAUDIT.Date,
            Format([Time], 'hh') AS [Hour],
            WHAUDIT.User,
            WHAUDIT.[ORDER],
            Count(WHAUDIT.PRODUCT) AS CountOfPRODUCT,
            Sum(WHAUDIT.QUANTITY) AS SumOfQUANTITY
          FROM
            WHAUDIT
          WHERE
            (
              (
                (WHAUDIT.type) = 'I11'
                Or (WHAUDIT.type) = ' 11'
              )
            )
          GROUP BY
            WHAUDIT.Date,
            Format([Time], 'hh'),
            WHAUDIT.User,
            WHAUDIT.[ORDER]
          HAVING
            (((WHAUDIT.Date) = '$date')) as temp456
          GROUP BY
            temp456.Hour,
            temp456.User,
            temp456.[ORDER]
        ) as temp123
      GROUP BY
        temp123.Hour,
        temp123.User
      ORDER BY
        temp123.Hour DESC;
  </code></pre>
  
  <p>I have been trying to produce the results using the echo function to populate a table, I haven't gotten as far as I have yet to make it work. It seems to be a query, within a query, within a query. Any advice would be much appreciated.</p>
  
  <p>I have tried square bracketing all instances of ORDER as it is apparently an essential part of it that won't be read properly without it. I have tried running it through a validator but this throws up various issues because of the brackets also. I also know that it seems to really not like the format Time section for some reason.</p>
  
  <p>The goal of this query is to be able to populate a table from the results on a Codeigniter view page. Any advice would be very much appreciated.</p>