PHP:动态传递URL中的参数

时间:2012-05-17 09:50:15

标签: php

我想以表格形式在数据库中显示数据。我写了以下代码

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['EmpID'] . "</td>";
echo "<td>" . $row['EmpName'] . "</td>";
echo "<td>" . $row['Designation'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td><a href='upasg3.php?empid='". $row['EmpID'] .">Edit</a ></td>";
echo "<td><a href='upasg3.php?empid='". $row['EmpID'] .">Delete</a ></td>"; 
echo "</tr>";
}

但我没有得到$ row [&#39; EmpID&#39;]的值与href的值连接。它使用empid = blank重定向到upasg3.php。 怎么解决这个问题?请帮忙

5 个答案:

答案 0 :(得分:4)

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['EmpID'] . "</td>";
echo "<td>" . $row['EmpName'] . "</td>";
echo "<td>" . $row['Designation'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>"; 
echo "</tr>";
}

引号。

答案 1 :(得分:2)

尝试在empid =

之后删除单引号

将它们放在这里:

echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>"; 

这将为您提供如下输出:

<a href='upasg3.php?empid=100'>

答案 2 :(得分:1)

尝试

echo "<td><a href='upasg3.php?empid=". $row['EmpID']."'>Edit</a ></td>";
                                    ^                 ^

答案 3 :(得分:1)

 <table width="100%" border="1">
  <tr>
 <td>ID</td>
<td>NAME</td>
<td>Designation</td>
<td>Salary</td>
<td>Edit</td>
  <td>Delete</td>
</tr>
<tr>
  <td><?=$row['EmpID']?></td>
<td><?=$row['EmpName']?></td>
<td><?=$row['Designation']?></td>
<td><?=$row['Salary']?></td>
<td><a href="upasg3.php?empid=<?=$row['EmpID']?>">Edit</a></td>
 <td><a href="upasg3.php?empid=<?=$row['EmpID']?>">Delete</a></td>
 </tr>

答案 4 :(得分:-1)

试试这个

echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Edit</a ></td>";
echo "<td><a href='upasg3.php?empid=". $row['EmpID'] ."'>Delete</a ></td>"; 

你的报价出错了。