-1

我刚学PHP,第一节课就发现了一个错误,我有几个小时尝试但不知道解决方案。

<td><?php echo $nomor=$nomor+1; ?></td>

我的PHP代码:

<?php
include "koneksi.php";
$query=mysql_query("select * from biodata");
$jumlah=mysql_num_rows($query);
echo "Jumlah data ada : ".$jumlah;
?>
<table border="1">
<tr>
<th>Nomor</th><th>Nama</th><th>Alamat</th><th>Usia</th><th>Aksi</th>
</tr>
<?php
while($row=mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $nomor=$nomor+1; ?></td>
 <td><?php echo $row['nama']; ?></td> 
<td><?php echo $row['alamat']; ?></td>
<td><?php echo $row['usia']; ?></td>
<td>
<a href="delete.php?id=<?php echo $row['id']; ?>" onclick="return confirm('Apakah anda yakin?')">Delete</a>
<a href="update.php?id=<?php echo $row['id']; ?>">Update</a>
</td>
<?php
}
?>
</table><br /> 
<a href="form.php">Input data form</a>

谢谢之前

4

4 回答 4

1
$nomor = $nomor + 1;
         ^^^^^^--- this is the EXACT spot of the error

You're trying to increment a variable that hasn't been defined yet. PHP has to READ the value in $nomor before it can +1 it, but $nomor hasn't been defined, so it doesn't exist, causing the warning. If you had:

$nomor = 0;
$nomor = $nomor + 1;

then there wouldn't be a problem.

于 2013-05-09T14:43:39.700 回答
1

你还没有初始化$nomor变量所以,php解释器,不知道它$nomor第一次“读取”它是什么

以这种方式修改您的代码

<?php
  $nomor=0;
  while($row=mysql_fetch_array($query)){
?>
于 2013-05-09T14:41:56.253 回答
0

The notice can be safely ignored but what it is saying is that $nomar was never initialized. In php initialization is done by assignment. So to make the notice go away just do $nomar = 0; The notice is coming from the reference on the right hand side of the assignment command, in initializing the variable it is using the variable which at that time is not initialized hence the notice.

于 2013-05-09T14:45:23.077 回答
0

欢迎来到 PHP 世界。

在第一次在流程中使用变量之前,您应该先定义它。

它不会导致错误,而是通知。

在使用 $nomor = $nomor + 1 之前

你必须定义 $nomor = 0; 首先退出while循环。

祝你好运

于 2013-05-09T14:46:09.563 回答