通过链接将多个变量从一个页面传递到另一个页面

时间:2011-11-13 02:12:07

标签: php html

我想通过点击链接一次将两个变量从一个页面传递到另一个页面。我有一个包含student_id和department_id字段的表。我运行一个while循环来弹出表中的所有数据。在这里,我想通过点击“删除”链接从另一个页面传递stu_id和dept_id。其中一个(stu_id或dept_id)可以单独传递到该页面,但是如何在同一时间将它们传递到一起。我的代码如下:

            if(isset($stu_id) || ($dept_id))
            {
                $order = "SELECT * FROM subscribed_student ORDER BY stu_id" or die (mysql_error());
                $result = mysql_query($order);  
                while($data = mysql_fetch_array($result))
                {
                echo("<tr>
                    <td style='padding:5px;'>$data[dept_id]</td>
                    <td style='padding:5px;'>$data[stu_id]</td>
                        <td style='padding:5px 10px;'>
                            <a href='subscribed_delete.php?stu_id=$row[stu_id]'>
                                Delete
                            </a>
                        </td>
                    </tr>");

谢谢

2 个答案:

答案 0 :(得分:3)

您可以更改此行:

<a href='subscribed_delete.php?stu_id=$row[stu_id]'>

进入这一个:

<a href='subscribed_delete.php?stu_id=$data[stu_id]&dept_id=$data[dept_id]'>

要向网址添加更多参数,您必须将每对(名称 - 值)与&分开。因此,你会有这样的事情:

URL?param1=val1&param2=val2&param3=val3...

答案 1 :(得分:1)

将网址更改为:

subscribed_delete.php?stu_id=$row[stu_id]&amp;dept_id=$data[dept_id]

(请注意'&amp; amp;',它在网址中显示为'&amp;',但需要在HTML中进行转义)

相关问题