-2

テーブル内のいくつかのデータ(名前とそれに関連付けられた番号)をチェックし、変数として設定する必要があるデータの1つを返すクエリがあります。

ただし、まだテーブルにないアイテム(新規参入者)をデータとして0と見なす必要があるが、データベースにないことは明らかであるため、問題が発生します。

スクリプトは次のとおりです。

        $jQuery = mysql_query("SELECT team, points FROM DCO_standings_teams WHERE competition='1' AND team='$teamname' AND year='$lastyear'");
{
    $points="$row[1]";
    $pointsmult = $points*50;
    $pointsoffer = $wage_offer/100;
    $bid_total = $pointsoffer+$pointsmult+$loyaltybonus;
}

この場合、チームAが昨年から12ポイントを獲得したとしましょう。$ pointsとして「12」を設定し、他のすべての計算を続行します。

私が必要としているのは、DCO_standings_teamsテーブルにレコードが見つからない場合、$pointsを0に設定する必要があることをサイトに伝えるためのものです。

どんな助けでもありがたいです、ありがとう!

4

4 に答える 4

0

あなたが何をしているのか考えてみましょう:

データベースにクエリを実行すると、結果が表示されます。結果がない場合は、あなたが言うように「新人」が必要です。

では、コードを続行する前に、「ポイント」の数を数えましょう。

他の人がほのめかしているように、mysql_ *以外の別の関数を使用する必要がありますが、ここではそれは私の関心事ではありません。

$jQuery = mysql_query("SELECT team, points FROM DCO_standings_teams WHERE competition='1' AND team='$teamname' AND year='$lastyear'");
$points = $row[1];
if($points == null) { // if there are no points (not 0, because that means there are 0 points)
     die("You are a newcomer."); 
     // do newcomer logic here 
} elseif($points > 0) { 
     //do other logic here
}
于 2013-01-02T19:39:56.510 に答える
0

あなたはただすることができます:

$result = mysql_query("SELECT team, points FROM DCO_standings_teams WHERE competition='1' AND team='{$teamname}' AND year='{$lastyear}'");

if(mysql_num_rows($result)) {
  $row = mysql_fetch_row($result);
  $points = $row[1];
}
else {
  $points = 0;
}

$pointsmult = $points*50;
$pointsoffer = $wage_offer/100;
$bid_total = $pointsoffer+$pointsmult+$loyaltybonus;
于 2013-01-02T19:43:17.860 に答える
0

あなたはすでにそれをしました...

if($points === null){
    $points = 0;
}

サイドポイント:

$points="$row[1]";意味がありません....ただ行う:$points = $row[1];

于 2013-01-02T19:33:42.787 に答える
0

値を整数にキャストします。そのようです:

$points = (int) $row[1];
于 2013-01-02T19:34:20.973 に答える