0

私の問題はこれです

私はこれを介してmysql行をフェッチしています

                $sql_istorrenthere = $this->query_silent("SELECT media_type
FROM " . DB_PREFIX . "auction_media WHERE
                auction_id='" . $item_details['auction_id'] . "'"); 
$row = mysql_fetch_array($sql_istorrenthere);

そして、これでそれを呼び出します

if ($row['media_type'] == 4) 
{

        $display_output = GMSG_TORRENT;}
        else
        {
        $display_output = GMSG_NOTORRENT;
        }
}

ただし、me​​dia_type には複数の値 (1,2,3,4) があり、4 が存在するかどうかを確認するにはどうすればよいですか? 今は、media_type が 4 に等しいかどうかをチェックしていて、それが false であると信じているため、間違った display_output が返されます

4

4 に答える 4

1

mysql_num_rows を使用して、行が返されたかどうかを判断できます。これは、クエリに「AND media_type = 4」を末尾に追加する検索条件を追加することで機能します。

if(mysql_num_rows($sql_istorrenthere)) {

} else {

}

// You can loop through records by doing the following, this prints out every media type :)
while ($row = mysql_fetch_array($sql_istorrenthere)) {
    echo $row['media_type'] . '<br />';
}
于 2012-05-05T02:15:03.163 に答える
0
// Comment the next line after you get what it is
@print ("Value of media type is: >>>".$row['media_type']."<<<"); // Line to be commented

if (isset($row['media_type']) && $row['media_type'] == 4) {
  $display_output = GMSG_TORRENT;
}
else {
  $display_output = GMSG_NOTORRENT;
}

すべてのメディア タイプを取得するには:

<?php
$sql_istorrenthere = $this->query_silent("SELECT media_type FROM " . DB_PREFIX . "auction_media"); 
while ($row = mysql_fetch_array($sql_istorrenthere)) {
// Comment the next line after you get what it is
  @print ("Value of media type is: >>>".$row['media_type']."<<<"); // Line to be commented

  if (isset($row['media_type']) && $row['media_type'] == 4) {
    $display_output = GMSG_TORRENT;
  }
  else {
    $display_output = GMSG_NOTORRENT;
  }

}
于 2012-05-05T02:15:59.530 に答える
0

クエリに「AND media_type = '4'」を追加するだけです。ただし、実際にはパラメーター化されたクエリを使用する必要があります。

クエリに「AND media_type = '4'」が含まれたら、RowCount を確認できます。

于 2012-05-05T02:16:08.517 に答える
0

もっと良い方法があるかもしれませんが、ここに 1 つのアイデアを示します。

$media_type_ids = explode(',', $row['media_type']);
if (array_search(4, $media_type_ids) !== FALSE) {
    // found
}

データベースクエリでこれをその場で行うことさえ可能かもしれません...潜在的に。

于 2012-05-05T02:17:11.027 に答える