doubeijian2257 2011-12-28 04:38
浏览 76
已采纳

MySQL in_array函数 - 第二个参数无效

I'm trying to determine whether or not the user has voted on a certain item and changing the image for the vote icon accordingly.

$user_likes = mysql_query("SELECT * from ratings WHERE userid = '$uid' AND aggregate = 1");
while ($row_likes = mysql_fetch_array($user_likes)) {
$row_likes['imageid'] = $likes_array;
}

Now in my content, I have a PHP foreach that returns a menu item for each submission (that is what users can vote on), the $image['idnum'] is the ID value for that individual image. The 'ratings' table seen in the query above is where I store votes like this: user id, image id, aggregate (in this case 1, to represent a like). Here is the in_array function that is giving me trouble:

if (in_array($image['idnum'], $likes_array)) {
    echo 'vote_triangle.png';
}

I'm getting the following error message:

Warning: in_array() [function.in-array]: Wrong datatype for second argument in (filename) on line 33

  • 写回答

1条回答 默认 最新

  • duanqiang2977 2011-12-28 04:41
    关注

    I think you have this part backwards:

    while ($row_likes = mysql_fetch_array($user_likes)) {
        $row_likes['imageid'] = $likes_array; // ????
    }
    

    Should be:

    // Initialize the array
    $likes_array = array();
    
    while ($row_likes = mysql_fetch_array($user_likes)) {
         $likes_array[] = $row_likes['imageid'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog