duanpao4172 2013-12-21 14:58
浏览 9

如何从表中获取数组数据?

I have a tags_ids array 1,3,2 and

data in my table:

+---------+----------+
| user_id | tag_id   |
+---------+----------+
|       1 |        1 |
|       1 |        2 |
|       2 |        1 |
|       2 |        2 |
+---------+----------+

I want to get the users ids into array, but not working:

foreach ($tags_ids as $i)
    {
        if ($result = $mysqli->prepare("SELECT `user_id` FROM `mytable` WHERE `tag_id`=?"))
        {
            $result->bind_param("i",$i);
            $result->execute();
            $result->bind_result($d);
            $result->fetch();
            $result->close();
        }

        if (!in_array($d,$users_ids)) $users_ids[] = $d;
    }

My result is always 1. Whats I'm doing wrong, and can I do it in a more simple way?

  • 写回答

1条回答 默认 最新

  • dongza3124 2013-12-21 15:15
    关注

    you need a while loop, you can find it here for full assist:http://www.youtube.com/watch?v=hO0YOOeJrOE
    be sure to watch the other video's too, very helpfull.

    goodluck, PHPNoob

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动