php传递参数问题

时间:2012-06-07 18:34:48

标签: php parameters hyperlink echo

这是我的代码:

<?php
$lijstDoelmannen = mysql_query("SELECT * FROM Speler WHERE positie = 'Doelman' ORDER BY familienaam, voornaam");
$teller = 1;
while($rij = mysql_fetch_array($lijstDoelmannen))
{
    if($teller < 5){
        echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
            <br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
    }
}
?>

问题是在超链接中参数spelerId = spaces(未填写)。如果我回复$rij["id"],它会给我正确的价值。

4 个答案:

答案 0 :(得分:0)

<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">

你需要移动撇号:

<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>

在添加变量之前,它正在结束链接。

答案 1 :(得分:0)

你也可以这样做:

echo "<td><a href='spelerDetail.php?spelerId={$rij['id']}'

答案 2 :(得分:0)

'中的错误位置有href

"...<a href='spelerDetail.php?spelerId='" . $rij['id'] . ">..."

这应该是:

"...<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>..."

答案 3 :(得分:0)

while($rij = mysql_fetch_array($lijstDoelmannen))
{
if($teller < 5){
    echo "<td><a href='spelerDetail.php?spelerId='" . $rij['id'] . "><img src='images/spelers/unknown.png' alt='' width='50' />
        <br /><br />" . $rij["id"] . " " . $rij['familienaam'] . " " . $rij['voornaam'] . "</a></td>";
}
}
?>

我更喜欢用这种方式编写上述代码来解决这些类型的问题:

while($rij = mysql_fetch_array($lijstDoelmannen)){
if($teller < 5){ ?>
    <td><a href="spelerDetail.php?spelerId=<?php echo $rij['id'] ?>">
    <img src="images/spelers/unknown.png" alt="" width="50" />
    <br /><br /><?php echo $rij['id'] . " " . $rij['familienaam'] . " " . $rij['voornaam'] ?></a></td>
<?php }} ?>