簡體   English   中英

只有我的數據庫中的第一個數據顯示,但其他顯示但不在表上

[英]Only the first data display from my database but other shows but not on a table

請仔細查看我的代碼並幫助我修復代碼中的錯誤。 只有我的第一個數據顯示在我的視圖頁面上的表格中,但其他數據顯示在視圖頁面上而不是表格上。

我的圖像名稱和圖像本身已成功插入我的數據庫和我的圖像目錄,我將其命名為“上傳”,但圖像不會顯示在我的視圖頁面上。

<?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 
}
?>

通過快速查看,我看到你正在關閉while循環中的表。 你應該改變它

</tr>

並記住使用thead和tbody標簽。 結束循環后關閉tbody和table。

這需要在你的while循環之外。

echo "</table>";

<img src=\"upload/\"

僅指向上載目錄,您沒有指定實際圖像。 嘗試類似的東西:

echo "<td><h1><img src=\"upload/$row['image']\" height=35 width=35  /> $row['id']</h1></td>";

將表關閉選項卡移出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>";
 ?>

我在更新頁面上顯示我的身份信息有點困難。 我有兩個條目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");

?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM