0

phpファイルに次のクエリがあります。

    if ($user) { //user is logged in (which he is)
        $highscore = mysql_query("SELECT highscore FROM highscore WHERE fbID = $user"); //wil give 200
        $fb_country_str = nl;

        if (mysql_num_rows($highscore) == 0) { //if no result from highscore set it to 1
            $highscore = 1;
        } else { //if we do get a result, select the country (in this case it is: uk)
            $country = mysql_query("SELECT country FROM highscore WHERE fbID = $user");
            if (!($country == $fb_country_str)) { //if the country is NOT the same, update the country with $fb_country_str (which in this case it should update)
                $sql = mysql_query("UPDATE highscore SET country = $fb_country_str WHERE fbID = $user");
            }
        }
    }

現在、実行時に、countryukをnlに変更する必要があるデータベースは更新されません。なぜだめですか?私は何が欠けていますか?

敬具

4

4 に答える 4

1

mysql_query関数は文字列を返しません。他のmysql_*関数で使用できるリソースを返します(http://php.net/mysql_queryを参照) 。

したがって、変数$countryは期待したものではありません。国の文字列を取得するには、mysql_fetch_assocmysql_resultなどの関数を使用する必要があります

php.netのマニュアルページでサンプルを確認できます。また、 $ highscoreでmysql_num_rows関数を呼び出したときに、そのスクリプトですでに戻り値をリソースとして使用しました(スカラー値ではありません) 。

于 2012-05-26T11:09:47.110 に答える
0
   if ($user) { //user is logged in (which he is)
        $highscore = mysql_query("SELECT highscore FROM highscore WHERE fbID = $user"); //wil give 200
        $fb_country_str = "nl"; //It's a string , you need quotes.

        if (mysql_num_rows($highscore) == 0) { //if no result from highscore set it to 1
            $highscore = 1;
        } else { //if we do get a result, select the country (in this case it is: uk)
            $getCountry = mysql_query("SELECT country FROM highscore WHERE fbID = $user");
//NOTICE - COUNTRY IS NOT THE COUNTRY VALUE YET!
$country = mysql_fetch_array($country);
$country = $country['country'];
            if (!($country == $fb_country_str)) { //if the country is NOT the same, update the country with $fb_country_str (which in this case it should update)
                $sql = mysql_query("UPDATE highscore SET country = $fb_country_str WHERE fbID = $user");
            }
        }
    }
于 2012-05-26T11:09:27.367 に答える
0

$ user-クエリでブール値(ifステートメント内)、数値(正しく仮定した場合)として再処理します

于 2012-05-26T11:10:00.473 に答える
0

最後のif条件を変更します

if ($country != $fb_country_str) 
{ 
//if the country is NOT the same, update the country with $fb_country_str (which in this case it should update)
$sql = mysql_query("UPDATE highscore SET country = $fb_country_str WHERE fbID = $user");
}
于 2012-05-26T11:16:55.393 に答える