请仔细查看我的代码并帮我修复代码中的错误。只有我的第一个数据显示在我的视图页面的表格中,但其他数据显示在视图页面上而不是表格上。
我的图像名称和图像本身已成功插入我的数据库和我的图像目录中,我将其命名为“上传”,但图像不会显示在我的视图页面上。
<?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
}
?>
答案 0 :(得分:2)
通过快速查看,我看到你正在关闭while循环中的表。您应该将其更改为
</tr>
并记住使用thead和tbody标签。 结束循环后关闭tbody和table。
答案 1 :(得分:0)
这需要在你的while循环之外。
echo "</table>";
和
<img src=\"upload/\"
仅指向上传目录,您没有指定实际图像。尝试类似:
echo "<td><h1><img src=\"upload/$row['image']\" height=35 width=35 /> $row['id']</h1></td>";
答案 2 :(得分: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>";
?>
答案 3 :(得分:0)
我在更新页面上显示我的身份信息时遇到了一些困难。我有两个条目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");
?>