所以我试图从我拥有的数据库中显示一个数组。当我运行脚本脚本时,我收到内部服务器错误。现在我不确定这是否与我的配置脚本有关,或者我是否正在通过我的数组正常循环。
include 'config.php';
$conn = name2;
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Feild FROM Season 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Feild " . $row["Feild"]. " "<br>";
}
} else {
echo "0 results";
}
答案 0 :(得分:0)
您用于显示结果的语法不正确,请替换:
echo "Feild " . $row["Feild"]. " "<br>";
使用:
echo 'Feild '.$row["Feild"].'<br>';
答案 1 :(得分:0)
您尚未正确终止字符串。
替换
echo "Feild " . $row["Feild"]. " "<br>";
使用
echo "Feild " . $row["Feild"]. "<br>";
如果您启用了错误,则会收到错误,说明行号。
答案 2 :(得分:0)
我们需要知道您选择哪一列,&#34; SELECT Feild FROM Season 1 &#34;不是有效的。它应该是&#34; SELECT Feild FROM Season WHERE column =&#39; 1&#39; &#34;
考虑到这一点,这可以让您更接近解决方案:
include 'config.php';
$conn = name2;
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Feild FROM Season 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "Feild ". $row["Feild"] ."<br>";
}
} else {
echo "0 results";
}
答案 3 :(得分:0)
使用正确的语法
echo "Feild ".$row['Feild']."<br>";