<h1>Matches</h1>
<?php
$con=mysqli_connect("localhost","root","","esports");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM NA");
while($row = mysqli_fetch_array($result))
{
echo $row['team1'] . " vs. " . $row['team2'];
echo "<br>";
}
mysqli_close($con);
?>
我正在尝试使用它从MySQL数据库中获取信息,然后使用HTML表格将其显示在网页上。我对此有点新意,所以我该怎么做呢?任何帮助表示赞赏。
答案 0 :(得分:0)
您的查询似乎没有任何问题,因此如果您只想将其格式化为表格,则可以
echo "<table border=1>";
while ($row = mysql_fetch_array($result)
{
echo '<tr><td>';
echo $row['team1'];
echo '</td><td>';
echo $row['team2'];
echo '</td></tr>';
}
mysql_close($con);
答案 1 :(得分:0)
要连接到MySQL数据库,您需要使用mysql_connect并使用mysql_select_db选择数据库,最后执行mysql_fetch_array
<?php
$con =mysql_connect("localhost","root","","esports");
mysql_select_db('your data base');
$result = mysql_query($con,"SELECT * FROM NA");
while($row = mysql_fetch_array($result))
{
echo '<pre>';
print_r( $row);
echo '</pre>';
}
mysql_close($con);
?>