0

请查看我的代码并帮助我修复代码中的错误。只有我的第一个数据显示在我的视图页面上的表格上,但其他数据显示在视图页面上而不是表格上。

我的图像名称和图像本身已成功插入我的数据库和我命名为“上传”的图像目录,但图像不会显示在我的视图页面上。

<?php
include ("config.php");
// Retrieve data from database 

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
<th>address</th>
<th>nationality</th>
<th>accountnumber</th>
<th>accounttype</th>
<th>balance</th>
<th>passport</th>
<th>username</th>
<th>passport</th>
<th>update</th>
<th>delete</th>
</tr>";

while($row = mysql_fetch_array($result)){

  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['nationality'] . "</td>";
  echo "<td>" . $row['account'] . "</td>";
  echo "<td>" . $row['accounttype'] . "</td>";
  echo "<td>" . $row['balance'] . "</td>";
  echo "<td><h1><img src=\"upload/\" height=35 width=35  /> $row[id]</h1></td>";  
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";``
 echo "<td><a href=\"update.php?id=" . $row['id'] . "\">update</a></td>";
 echo "<td><a href=\"delete.php?id=" . $row['id'] . "\">delete</a></td>";
echo "</table>";

// close while loop 
}
?>
4

4 回答 4

2

通过快速查看,我看到您正在关闭 while 循环内的表格。您应该将其更改为

</tr>

并记住使用 thead 和 tbody 标签。结束循环后关闭 tbody 和 table。

于 2013-08-14T10:22:41.250 回答
0

我在更新页面上显示我的 ID 信息时遇到了一点困难。我有两个条目 6 和 7 如果我单击 id 6 上的更新,它将显示在我的更新页面上,但如果我单击 id 7 上的更新,在地址栏上,它将指示 id =7 但它仍会显示 id 6个信息。

这是我的显示代码,在我的更新页面上显示数据

 <?ph
 include ('config.php');  
 // Retrieve data from database 
 $sql="SELECT * FROM $tbl_name ";
 $result=mysql_query($sql);
 $row=mysql_fetch_array($result);
 ?>

其次,如果我更改更新页面的数据,更改不会反映在我的视图页面上。

<?php
include('config.php');
//This is the directory where images will be saved 
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$nationality=$_POST['nationality'];
$accountnumber=$_POST['account'];
$accounttype=$_POST['accounttype'];
$balance=$_POST['balance'];
$username=$_POST['username'];
$password=$_POST['password'];
$id=$_POST['id'];
// update data in mysql database 
$sql="UPDATE $tbl_name SET firstname='$firstname', lastname='$lastname', address='$address', nationality='$nationality',accountnumber='$account',accounttype='$accounttype',balance='$balance',username='$username',password='$password'
WHERE id='$id'";
$result=mysql_query($sql);

header ("Location: details.php");

?>
于 2013-08-15T06:58:01.940 回答
0

这需要在您的 while 循环之外。

echo "</table>";

<img src=\"upload/\"

仅指向上传目录,您没有指定实际图像。尝试类似:

echo "<td><h1><img src=\"upload/$row['image']\" height=35 width=35  /> $row['id']</h1></td>";
于 2013-08-14T10:24:21.100 回答
0

将表格关闭选项卡移出 while 循环将解决第一个问题。

更改代码如下解决图像问题。

echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';

您的代码应如下所示。

<?php
include ("config.php");
// Retrieve data from database 

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>firstname</th>
<th>lastname</th>
<th>address</th>
<th>nationality</th>
<th>accountnumber</th>
<th>accounttype</th>
<th>balance</th>
<th>passport</th>
<th>username</th>
<th>passport</th>
<th>update</th>
<th>delete</th>
</tr>";

while($row = mysql_fetch_array($result)){

  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['firstname'] . "</td>";
  echo "<td>" . $row['lastname'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['nationality'] . "</td>";
  echo "<td>" . $row['account'] . "</td>";
  echo "<td>" . $row['accounttype'] . "</td>";
  echo "<td>" . $row['balance'] . "</td>";
  echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';  
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['password'] . "</td>";``
  echo "<td><a href=\"update.php?id=" . $row['id'] . "\">update</a></td>";
  echo "<td><a href=\"delete.php?id=" . $row['id'] . "\">delete</a></td>";
 echo "</tr>";

// close while loop 
}
 echo "</table>";
 ?>
于 2013-08-14T11:05:20.333 回答