shaydes Posted July 31, 2011 Share Posted July 31, 2011 I am using this query to get data: $cids = "212, 225"; $query = "select users.id as id, name, convert(text, intro) as intro from users, sections where status=1 and sections.user_id = users.id and users.id in ($cids)"; $result = mssql_query($query); [/Code] This is the message I get: PHP Warning: mssql_query(): message: Incorrect syntax near ','. (severity 15) in /var/www/msq/select-intro.php on line 495, referer: http://abc.domain.com/select-intro.php. Before executing the query, the string looks like this: select users.id as id, name, convert(text, intro) as intro from users, sections where status=1 and sections.user_id = users.id and users.id in (212, 225) The comma separated list ($cids) is generated by imploding an array on integers. If I copy the string from debugging output, there is no PHP Warning but if I use $cids, there is. Quote Link to comment https://forums.phpfreaks.com/topic/243337-php-warning-mssql_query-message-incorrect-syntax-near/ Share on other sites More sharing options...
Muddy_Funster Posted August 9, 2011 Share Posted August 9, 2011 You say your values for @cids is coming from an array, yet your sample code shows it being hard set. Could you clarify which is accurate? Quote Link to comment https://forums.phpfreaks.com/topic/243337-php-warning-mssql_query-message-incorrect-syntax-near/#findComment-1254766 Share on other sites More sharing options...
shaydes Posted August 10, 2011 Author Share Posted August 10, 2011 The values come from the database: $query = select id from users where active =1; ... while ($row = mssql_fetch_row($result) $ids[$row->id] = $row->id; The the array of ids is converted to comma separated list $cids = implode(",", $ids); [/Code] I had used sample values to illustrate. Quote Link to comment https://forums.phpfreaks.com/topic/243337-php-warning-mssql_query-message-incorrect-syntax-near/#findComment-1255467 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.