任何人都可以帮助我如何从多个 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);
?>
我搜索谷歌发现解决方案是使用联合,但我不断收到错误“未定义索引 t”