-2
<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 表将其显示到网页上。我对此有点陌生,那么我该怎么做呢?任何帮助表示赞赏。

4

2 回答 2

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);
?>
于 2013-08-14T00:33:42.500 回答
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);
于 2013-08-14T00:22:49.053 回答