/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] wrong datatype

[code=php]<?
$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)){ ?>[/code]

[B]Warning[/B]: in_array() [function.in-array]: Wrong datatype for second argument in [B]C:Program Filesxampphtdocscoldwaruser.php[/B] on line [B]38[/B]

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

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Jan 28.2007 — [code=php]<?
# Code In between[/QUOTE]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? [B]$row [/B]wouldn't contain an [B]array[/B] but [B]false[/B].

Do you have[code=php]if (mysql_num_rows($sql) == 1)[/code]
in there?
Copy linkTweet thisAlerts:
@The_Little_GuyauthorJan 28.2007 — No, I have nothing in there that has to do with this, its all HTML.
Copy linkTweet thisAlerts:
@NightShift58Jan 28.2007 — 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.[code=php]<?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...";
}
?>[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyauthorJan 28.2007 — Hmmm..... I get: The information you were looking for could not be found. We tried and tried, but no chance, etc...
Copy linkTweet thisAlerts:
@NightShift58Jan 28.2007 — ... which means your query is not pulling in any data...

and that would be the next question... ?
Copy linkTweet thisAlerts:
@The_Little_GuyauthorJan 28.2007 — 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']
  • Copy linkTweet thisAlerts:
    @NightShift58Jan 28.2007 — 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?
    Copy linkTweet thisAlerts:
    @The_Little_GuyauthorJan 28.2007 — 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.
    Copy linkTweet thisAlerts:
    @NightShift58Jan 28.2007 — You're welcome!
    ×

    Success!

    Help @The_Little_Guy spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...