我正在尝试创建一个PHP循环来向玩家展示他们参与的锦标赛。我在phpMyAdmin上尝试了这个功能,我得到了我想要的结果。但是当我尝试在PHP上运行这个简单的脚本时,它输出为0行。
的index.php
chdir("../"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
if($mybb->user['uid']) {
$sql = "SELECT * FROM players, tourneys WHERE players.forumname = 1 AND players.tid = tourneys.id";
$result = mysqli_query($conn, $sql);
// output data of each row
if (mysqli_num_rows($result) > 0) {
// output data of each ro
while($row = mysqli_fetch_assoc($result)) {
$name = $row['name'];
$date = $row['date'];
$time = $row['time'];
echo $name;
echo $date;
echo $time;
}
} else {
echo "0 rows";
}
}
答案 0 :(得分:0)
问题不在" if($ mybb-> user [' uid']){"正如@Dagon所建议的那样。尝试保留缩进的代码以避免这种混淆。运行下面的代码并发布DB错误输出。
试试这个:
<?php
chdir("../"); // path to MyBB
define("IN_MYBB", 1);
require("./global.php");
if ($mybb->user['uid']) {
$player_forumname = '1';
// Return only the necessary fields
$sql = "SELECT tourneys.name, tourneys.date, tourneys.time
FROM tourneys
INNER JOIN players ON players.tid = tourneys.id
WHERE players.forumname = {$player_forumname}";
$result = mysqli_query($conn, $sql);
// If the query fails display the error
if ($result === FALSE) {
die('MySQLi Error: ' . mysqli_error($conn));
}
if (mysqli_num_rows($result) == 0) {
die('0 rows');
}
// Returns only the associative array
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$name = $row['name'];
$date = $row['date'];
$time = $row['time'];
echo 'Name:',$row['name'],'Date:',$row['date'],'Time:',$row['time'];
}
}