2

当我单击链接字段时,我被困在一个想要查看 mysql 表的其他字段的地方。这是用于在链接中创建字段的代码

<td><a href="fieldview.php?id=' .$row[0]. '"><b>' .$row[1]. '</b></td>

这里 $row[0] 是 mysql table(exampletable) 中名为“id”的字段,而 $row[1] 是名为“title”的字段。现在,在“fieldview.php”页面上,我使用此代码查看其他字段:

$id=$_GET['id'];
$sql="SELECT * FROM exampletable WHERE id= '$id'";
$result=mysql_query($sql);

while ($row=mysql_fetch_array($result))
{
  echo '<table id="customers">';
  echo '<tr><th>Field 1</th> <th>Field 2</th> <th>Field 3</th></tr>';
  echo '<tr class="alt"><td><b>' .$row[1]. '</b></td><td><b>' .$row[2]. '</b></td><td><b>Today!</b></td></tr>';
  echo '</table>';
}

但是我在那个页面上什么也没有。请问谁能告诉我解决办法是什么?

4

2 回答 2

1

试试 jakenoble 的建议。如果您没有看到问题,可能是因为您首先构建链接的方式。

尝试修改为这样的东西:

<td><a href="fieldview.php?id=<?php echo $row[0] ?>"><b> <?php echo $row[1] ?></b></a></td>
于 2013-07-23T16:18:03.723 回答
0

你连接你的数据库了吗?

首先连接数据库!!!!!!!!!

尝试回声:

echo $_GET['id'];

在你的文件中。

但是我在那个页面上什么也没有。请问谁能告诉我解决办法是什么?

您是否得到了没有任何内容的 HTML 表格?

尝试以下操作:

    <?php
    // Create connection
    $con=mysqli_connect("example.com","peter","abc123","my_db");

    // Check connection
    if (mysqli_connect_errno($con))
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    echo $id=$_GET['id'];
    $sql="SELECT * FROM exampletable WHERE id= '$id'";
    $result=mysql_query($sql);

    while ($row=mysql_fetch_array($result))
    { 
    ?>
    <table id="customers">
 <tr><th>Field 1</th> <th>Field 2</th> <th>Field 3</th></tr>
 <tr class="alt"><td><b><?php echo $row[0]; ?></b></td><td><b><?php echo $row[1]; ?></b></td><td><b>Today!</b></td></tr>
    </table>
    <?
    }
    ?>

如果您的 HTML 表中没有数据,则在您的查询浏览器中使用 ID 运行 MySQL 查询,以查找您有该 ID 的数据。

请指定您尝试过的内容?

于 2013-07-23T16:21:16.690 回答