根据另一个表的信息从表创建循环

I've a table called "projects" :

table projects

and one other called "user_to_project" that defined which user follow wich projects (in this example, the "user_id" 1 follow "project_id" 2,3)

table "user_to_project"

I'm looking for a function to display all the project following by an user. I was thinking something like this :

function getUserProjects($user_id){
    global $db;    
    return $db->query('SELECT * FROM `projects` INNER JOIN `user_to_project` ON (`user_to_project`.`project_id` = `user_to_project`.`user_id`) WHERE `user_to_project`.`user_id` = ' . (int)$user_id );

}

But it doesn't work...

Do

  $sql = 'SELECT a.*,b.* FROM `projects` a 
  INNER JOIN `user_to_project` b
  ON (b.project_id = a.project_id) 
  WHERE b.user_id = ' . (int)$user_id;