doupeizheng3918 2018-09-12 08:56
浏览 26

从表中选择(选择)不工作,我做错了什么? [重复]

$sql = "SELECT * FROM groups WHERE id IN (SELECT group FROM groupmembers WHERE user = $my_userid)";

Okay so the structure of groups looks like this: name, id, privacy

and the structure of groupmembers looks like this: group, user

The variable $my_userid has already been defined and has the value of 1.

I'm trying to execute the sql above and then include a file which will echo the group name, i've added myself to 2 groups so i should echo test1 and test2, the included file works, i've tried including it twice just to see if there was any problem with it and it wasn't. I cannot see what's wrong, i've looked for a fix here but haven't found it. The whole php code is below:

<?php
$sql = "SELECT * FROM groups WHERE id IN (SELECT group FROM groupmembers WHERE user = $my_userid)";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
      $g_name = $row['name'];
      $g_id = $row['id'];
      include 'files/social/group.php';
    }
} else {
   // Nothing to display, user is not in any group.
}
?> 
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 mmocr的训练错误,结果全为0
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀