私はビデオゲームの在庫を格納するためのテーブルを持つSQLデータベースを持っています。次のPHPコードはそのデータベースと特定のテーブルにアクセスし、10個または在庫があるビデオゲームだけを印刷したいと考えています。ビデオゲームの数量は、私の "在庫"テーブルに "数量"として保存されています。進んでいただきありがとうございます。PHPとSQLデータベース
<?php
// Construct query
$query = "SELECT * FROM inventory";
// Perform the query, gather results
$results = mysql_query($query)
or die ("Sorry, could not get the data ". mysql_error());
echo "<div style=margin-bottom:10px;>Number of games found with quantity > 10 is ". "</div>\n";
// Create loop to print all found records
// That are contained inside of the $results variable
for($i = 0; $i < mysql_num_rows($results); $i++) {
if ($gamearray['quantity'] > 10) {
$gamearray = mysql_fetch_array($results);
echo "<div>Title of game is ". $gamearray['title'] ."</div>\n";
echo "<div>Quantity in stock is ". $gamearray['quantity'] ."</div>\n";
echo "<div style=margin-bottom:10px;>With a critic score of ". $gamearray['metascore'] ." This game is</div>\n";
}
}
?>
SQLのWHERE句を読む必要があるようです。 – jmoerdyk
**警告**:PHPを習得しているだけの方は、古い['mysql_query'](http://php.net/manual/en/function.mysql-query.php)インタフェースを学ばないでください。それはひどいので、PHP 7では削除されました。[PDOは学ぶのが難しくありません](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo- for database-access /)、[PHP The Right Way](http://www.phptherightway.com/)のようなガイドはベストプラクティスの説明に役立ちます。 **あなたのユーザーパラメータが[正しくエスケープされている](http://bobby-tables.com/php)か、重大な[SQLインジェクションバグ](http://bobby-tables.com/ )。 – tadman