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 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?