Jaynesh Posted July 12, 2011 Share Posted July 12, 2011 hi is it possible to add comments in sql queries. my sql query has gotten so complicated to the point that I don't know which part does what. Quote Link to comment https://forums.phpfreaks.com/topic/241790-adding-comments-in-queries/ Share on other sites More sharing options...
cyberRobot Posted July 12, 2011 Share Posted July 12, 2011 You could add PHP comments that describe the query: http://php.net/manual/en/language.basic-syntax.comments.php Quote Link to comment https://forums.phpfreaks.com/topic/241790-adding-comments-in-queries/#findComment-1241753 Share on other sites More sharing options...
Jaynesh Posted July 12, 2011 Author Share Posted July 12, 2011 Hi. Yes but how can I add this into the query. for e.g $query = "SELECT $select //from FROM dbPosts //left join LEFT JOIN dbUsers ON dbPosts.username_id = dbUsers.id //left LEFT JOIN dbFriends ON (dbPosts.username_id = dbFriends.my_id)" Quote Link to comment https://forums.phpfreaks.com/topic/241790-adding-comments-in-queries/#findComment-1241755 Share on other sites More sharing options...
cyberRobot Posted July 12, 2011 Share Posted July 12, 2011 Instead of embeding the comments in the query, you could do something like: $query = "SELECT $select " . "FROM dbPosts " . //from "LEFT JOIN dbUsers " . //left join "ON dbPosts.username_id = dbUsers.id " . "LEFT JOIN dbFriends " . //left "ON (dbPosts.username_id = dbFriends.my_id)"; Quote Link to comment https://forums.phpfreaks.com/topic/241790-adding-comments-in-queries/#findComment-1241762 Share on other sites More sharing options...
trq Posted July 12, 2011 Share Posted July 12, 2011 mysql uses -- to delimit a comment. $query = "SELECT $select -- from FROM dbPosts -- left join LEFT JOIN dbUsers ON dbPosts.username_id = dbUsers.id -- left LEFT JOIN dbFriends ON (dbPosts.username_id = dbFriends.my_id)"; Quote Link to comment https://forums.phpfreaks.com/topic/241790-adding-comments-in-queries/#findComment-1241765 Share on other sites More sharing options...
cyberRobot Posted July 12, 2011 Share Posted July 12, 2011 Thanks for jumping in! I tend to forget about MySQL options. Quote Link to comment https://forums.phpfreaks.com/topic/241790-adding-comments-in-queries/#findComment-1241768 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.