誰でも複数のMySQLテーブルから選択し、phpを使用してゲームプレイ制限15でソートする方法を教えてもらえますか?
<?php
//$query = "SELECT id, gamename, gameplayed FROM action, adventure, augur, beauty, chess, joke, mmorpg, multiplayer, platform, puzzle, racing, shooting, sport, stratergy WHERE id = :id";
$query = '
SELECT id, gamename, gameplayed FROM((
SELECT id, gamename, gameplayed
FROM action
ORDER BY gameplayed
DESC LIMIT 15
) UNION (
SELECT id, gamename, gameplayed
FROM adventure
ORDER BY gameplayed
DESC LIMIT 15
))as t ORDER BY gameplayed';
$query_params = array(':id' => '1');
//$query = "SELECT id, gamename FROM action, adventure, augur, beauty, chess, joke, mmorpg, multiplayer, platform, puzzle, racing, shooting, sport, stratergy ORDER BY gameplayed DESC LIMIT 15";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$stmt->execute($query_params);
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
$rows = $stmt->fetchAll();
foreach($rows as $row):
echo $rows['t'];
endforeach;
unset($row);
?>
Google で検索すると、解決策が union を使用していることがわかりましたが、「インデックス t を未定義」というエラーが表示され続けます