5 Replies Latest reply: Oct 8, 2011 5:48 AM by TCarp RSS

    Beginner: Getting syntax error on WHERE clause in SELECT

    TCarp Community Member

      I'm very new to php and mySQL.  Am using DW master/detail to generate to basic code I need.  One thing I need to do is modify a select statement in the master to include a WHERE clause to limit the selection to a particular value in one field.

       

      I'm getting a syntax error with the WHERE clause I'm adding to the map select statement.

       

      This is the portion of the error message showing the error location:

       

      'WHERE Group='Community' LIMIT 0, 10'

       

      The php that generated the select is:

       

      $query_maps = "SELECT * FROM tblmaps ORDER BY tblmaps.DispSeq";

      $query_limit_maps = sprintf("%s WHERE Group='%s' LIMIT %d, %d", $query_maps, $selectGroup, $startRow_maps, $maxRows_maps);

       

      This approach to creating the select statement is from the code generated for the master page.  It adds the LIMIT clause.  All I did was add the "WHERE Group='%s' and the $selectGroup variable which comes from earlier code.  You can see that the $selectGroup variable is equal to the "Community: group.

       

      I've scanned the web to see what syntax error I might be making but haven't found anything that explains it.

       

      The full resolved select statement is:

       

      SELECT * FROM tblmaps ORDER BY tblmaps.DispSeq WHERE Group='Community' LIMIT 0,10

       

      What am I not seeing?

       

      Tom