www.webdeveloper.com
Results 1 to 10 of 10

Thread: [RESOLVED] wrong datatype

  1. #1
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287

    resolved [RESOLVED] wrong datatype

    PHP Code:
    <?
    $sql 
    mysql_query("SELECT users.*, races.* FROM users,races WHERE users.user_id=races.founder_id LIMIT 1")or die(mysql_error());
    $row mysql_fetch_array($sql);

    # Code In between

     
    if($row['race']==0&&!in_array($_SESSION['id'],$row)){ ?>

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\Program Files\xampp\htdocs\coldwar\user.php on line 38


    I don't see how this is the wrong datatype, can someone help me?

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Quote Originally Posted by The Little Guy
    [PHP]<?
    # Code In between
    I can't tell from "Code In Between" if you checked on how many records where retrieved from the tables. What if no records were retrieved? $row wouldn't contain an array but false.

    Do you have
    PHP Code:
    if (mysql_num_rows($sql) == 1
    in there?

  3. #3
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    No, I have nothing in there that has to do with this, its all HTML.

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Well, you need it in there somehow... How do you know if your query returned any data? You need to check that first and, if you're gettung the data you expected, proceed. If not, you need to find an appropriate exit.
    PHP Code:
    <?php
    $sql 
    mysql_query("SELECT users.*, races.* FROM users,races WHERE users.user_id=races.founder_id LIMIT 1")or die(mysql_error()); 

    if (
    mysql_num_rows($sql) == 1) {
      
    $row mysql_fetch_array($sql); 
      
    # Code In between
      
    if($row['race']==0&&!in_array($_SESSION['id'],$row)){
        
    # More Code In between
      
    }
    } else {
      echo 
    "The information you were looking for could not be found. We tried and tried, but no chance, etc...";
    }
     
    ?>

  5. #5
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    Hmmm..... I get: The information you were looking for could not be found. We tried and tried, but no chance, etc...

  6. #6
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    ... which means your query is not pulling in any data...

    and that would be the next question...

  7. #7
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    Which would be???


    Is my search query valid? I don't get any errors, so I'm guessing it is.

    - I want to select from both tables (users, races)
    - Where the id's match (user_id, founder_id)
    - I only want it to select where the user_id and founder_id = $_SESSION['id']

  8. #8
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    The query seems syntactically valid - or, as you said, you would be getting an error. I just ran an almost identical query and it worked.

    Is the data there to support the query? Have you doing it manually with phpMyAdmin or similar tool?

  9. #9
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    OMG I'm Sorry, I realized that during testing, I deleted from the table races, and the table was empty. Anyways that being said, I think I need to add the mysql_num_rows function and I'll be good to go so I don't get that error message again when no rows are found! Thank You for your help.

  10. #10
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    You're welcome!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles