douduan5753 2014-09-04 19:25
浏览 50

从查询中返回用户对象数组

I am calling a MySQL query that returns an array of user IDs. I want to pass this array if IDs to get_users to create an array of users, but I can't seem to get the code right.

My code is currently....

// get all users who have done something in the last 20 mins, or just the top 30 if there are more.
$get_user_activity='SELECT user_id FROM wp_wol WHERE last_action_date >= ( NOW( ) -2200 ) ORDER BY last_action_date DESC LIMIT 0 , 30';
$user_list = mysql_query ( $get_user_activity);
$args = wp_parse_args( $args, array( 'include' => $user_list ));
$users = get_users( 'include' => $args ); 

Thank you in advance.

  • 写回答

1条回答 默认 最新

  • dongni3854 2014-09-04 19:35
    关注

    One problem you have is that $user_list is not what you expect it to be.

    You treat it like it is an array with user ID's but mysql_query() returns false or a resource on success.

    You need to fetch all your rows first before you can use it in wp_parse_args() / get_users().

    Something like:

    $success = mysql_query($get_user_activity);
    $user_list = array();
    while ($row = mysql_fetch_assoc($result)) {
        $user_list[] = $row['user_id'];
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大