I have a database that hosts a couple of tables inside a Drupal install. One of these tables is for activities and the other one is places. I have users create places and then add activities that can be done at these places and once you’ve created an activity you can edit it if you’re the owner of it. So, I have this query:
$activ = db_query("SELECT a.aid, a.name, a.picture, a.data, a.time, p.name as place_name FROM activities a, places p WHERE p.pid = ANY (SELECT pla.pid FROM places pla WHERE pla.uid = :uid) ORDER BY a.activity_date ASC", array(':uid' => $user->uid));
That, as I understand would list the activities the logged in user has created and therefore owns, however, if there is more than one activity created by users the logged in user can see other people’s activities and edit them. I think the problem may be in the ANY part of the query but I’m not able to figure out what is wrong. Any ideas?
I’m guessing activity table has “pid” column (place id):