PHP表超链接

时间:2013-04-17 11:38:58

标签: php hyperlink

我有一个从mysql返回信息的表。但是,我希望超链接每个邮政编码,以便当用户点击一个邮政编码时,它会将它们重定向到适当的页面。这是表中的代码:

<table style="border:2px solid black; border-collapse:collapse;" cellspacing="2" cellpadding="2" align="center">
<tr align="center" width="auto">
<td bgcolor="#66CCFF" style="border:2px solid black;"><b>&nbsp;Consultation Date&nbsp;</b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b>&nbsp;Patient Health Care Number&nbsp;</b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b>&nbsp;Location&nbsp;</b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b>&nbsp;Post Code&nbsp;</b></td>
<td bgcolor="#66CCFF" style="border:2px solid black;"><b>&nbsp;Update Record&nbsp;</b></td>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"Consultation Date");
$f2=mysql_result($result,$i,"Patient HCN");
$f3=mysql_result($result,$i,"Location");
$f4=mysql_result($result,$i,"Post Code");
?>

<tr>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo $f1; ?></td>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><b><?php echo $f2; ?></b></td>
<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo $f3; ?></td>

<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo "<a href=\"coveragehcp.php?patient= ". $f2 ."\">"?><b><?php echo $f4; ?></b></td>

<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo "<button onclick=\"window.location.href='hcp_form_update.php?patient=$f2'\">"?>Update Record</button></td> <!-- This button redirects the user to the auto-populated form that holds the patients information which allows the user to update it -->
</tr>

<?php
$i++;
}
?>

然而,当用户点击下面的链接时,我希望它根据点击的邮政编码将它们重定向到另一个页面。

<td align="center" bgcolor="#FFFFFF" style="border:2px solid black;"><?php echo "<a href=\"coveragehcp.php?patient= ". $f2 ."\">"?><b><?php echo $f4; ?></b></td>

1 个答案:

答案 0 :(得分:0)

我要做的是将后置代码用作GET中的参数,然后使用$_GET['postcode']来实现应该为用户呈现的页面。

所以你的链接的PHP代码看起来像:

<a href=\"coveragehcp.php?patient= ".$f2."&postcode=".$f4."\">"?><b><?php echo $f4; ?></b></td>

并在coveragehcp.php页面上使用此

$postcode = $_GET['postcode'];
if(!empty($postcode))
{
    if($postcode == 90210) {
        //Echo beverly hills page
    }
    else {
        //Echo default page
    }
}