0

这是我的代码:

<?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 = 空格(未填写)。如果我 echo $rij["id"],它会给我正确的价值。

4

4 回答 4

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

您需要移动撇号:

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

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

于 2012-06-07T18:36:48.183 回答
0

你也可以这样做:

echo "<td><a href='spelerDetail.php?spelerId={$rij['id']}'
于 2012-06-07T18:41:41.193 回答
0

'在你的href.

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

这应该是:

"...<a href='spelerDetail.php?spelerId=" . $rij['id'] . "'>..."
于 2012-06-07T18:42:40.507 回答
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 }} ?>
于 2012-06-07T18:48:05.607 回答