简体   繁体   中英

While Loop taking ID value for a href

while loop:

   <tbody>
                        <?php while($row=$result->fetch_assoc()){ ?>
                            <tr> 
                                <td><?= $row['id']; ?></td>
                                <td><?= $row['fornavn']; ?></td>
                                <td><?= $row['efternavn']; ?></td>
                                <td><?= $row['mail']; ?></td>
                                <td><?= $row['kursistnummer']; ?></td>
                                <td><?= $row['unilogin']; ?></td>
                                <td>
                                <a href="read.php?id='. $row['id'] .'" class="mr-3" title="View Record" data-toggle="tooltip"><span class="fa fa-eye"></span></a>
                                </td>
                            </tr>
                        <?php } ?>
                    </tbody>

when I press the a href for each record it always results in this url http://localhost/helloworld/read.php?id=%27.%20$row[%27id%27]%20.%27

I think its the syntax of the ---- > href="read.php?id='. $row['id'].'" but I've tried all the variations that I can find as a php beginner, it's driving me nuts!

PHP shorthand tag for echo is missing in href link.

This Code snippet should work:

<a href="<?= 'read.php?id='. $row['id'] ?>" class="mr-3" title="View Record" data-toggle="tooltip"><span class="fa fa-eye"></span></a>

use "" for the id attribute because you use '' outside the . $row['id']. . $row['id'].

So like this:

href="read.php?id='. $row["id"] .'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM