2011-12-28 04:38
浏览 46

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() []: Wrong datatype for second argument in (filename) on line 33

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanqiang2977
    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'];
    点赞 评论