1

我需要显示一个表格,显示将笑话输入数据库的用户。我有一个笑话名称“笑话”的表和一个名为“作者”的用户的表笑话表有 id、joketext、jokedate、authorid 作者表有 id、名称、电子邮件所以“authorid”与“ id' 在作者表中。

<?php
$con=mysqli_connect("localhost","user","password","ijdb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysql_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");

echo "<form action='delete1.php' method='post'>
<table border='1'>
<tr>
<th>Joke</th>
<th>Date</th>
<th>Name</th>
<th>Email</th>
<th>Delete</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['joketext'] . "</td>";
  echo "<td>" . $row['jokedate'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td><input type='submit' name='deleteItem' value='".$row['id']."' /></td>";
  echo "</tr>";
  }
  echo "</table>";

  echo "</form></br>";

mysqli_close($con);
?>

我收到此错误警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,布尔值在第 22 行的 C:\xampp\htdocs\kimmy\jokes\joke1.php 和一个空表中给出

谢谢

4

3 回答 3

2

错误是您使用的是 mysql_query 而不是 mysqli_query

所以代码变成

<?php
$con=mysqli_connect("localhost","user","password","ijdb");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
ON authorid = author.id");

echo "<form action='delete1.php' method='post'>
<table border='1'>
<tr>
<th>Joke</th>
<th>Date</th>
<th>Name</th>
<th>Email</th>
<th>Delete</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['joketext'] . "</td>";
  echo "<td>" . $row['jokedate'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td><input type='submit' name='deleteItem' value='".$row['id']."' /></td>";
  echo "</tr>";
  }
  echo "</table>";

  echo "</form></br>";

mysqli_close($con);
?>
于 2013-08-27T08:00:17.507 回答
2

它应该是:

$result = mysqli_query($con, "SELECT joke.id, joketext, name, email FROM joke INNER JOIN author
                              ON authorid = author.id");

使用扩展程序mysql_query()时无法使用。mysqli

于 2013-08-27T08:01:03.657 回答
1

尝试更改以下内容

$result = mysql_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author

ON authorid = author.id");

$result = mysqli_query("SELECT joke.id, joketext, name, email FROM joke INNER JOIN author

ON authorid = author.id");

您正在使用 mysql_query 而不是 mysqli_query

于 2013-08-27T08:01:05.203 回答