Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 只有第一个数据显示在我的数据库中,但其他数据显示在表上,而不是在表上_Php_Cakephp - Fatal编程技术网

Php 只有第一个数据显示在我的数据库中,但其他数据显示在表上,而不是在表上

Php 只有第一个数据显示在我的数据库中,但其他数据显示在表上,而不是在表上,php,cakephp,Php,Cakephp,请查看我的代码并帮助我修复代码中的错误。只有我的第一个数据显示在“我的视图”页的表上,而其他数据显示在“视图”页上,而不是表上 我的图像名称和图像本身已成功插入我的数据库和我的图像目录,我将其命名为“上载”,但图像不会显示在我的查看页面上 <?php include ("config.php"); // Retrieve data from database $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); echo

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

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

<?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 
}
?>
<?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");

?>

通过快速查看,我看到您正在关闭while循环中的表。你应该把它换成一个

</tr>

记住使用thead和tbody标签。
结束循环后关闭t正文和表格。

这需要在while循环之外

echo "</table>";
echo”“;


仅指向上载目录,您没有指定实际图像。尝试以下方法:

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

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

按如下所示更改代码以解决图像问题

echo '<td><img src="upload/'.$row['your image name'].'" height=35 width=35 ></td>';
echo';
您的代码应该如下所示

<?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>";
 ?>

我在更新页面上显示我的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");
// 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 
}
?>
<?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");

?>

非常感谢。表格问题起作用了,但是图像代码不起作用,但是我这样使用它,它起作用了。谢谢,上帝保佑。回显“$row[id]”;我不知道列名,因为您从未指定它,所以我只是猜测。:)祝你好运