dsfykqq3403 2017-01-23 15:39
浏览 29

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

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...

  • 写回答

1条回答 默认 最新

  • doujianmin6527 2017-01-23 15:45
    关注

    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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥15 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)