Home > Enterprise >  While Loop taking ID value for a href
While Loop taking ID value for a href

Time:09-19

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'] .'"  title="View Record" data-toggle="tooltip"><span ></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='. $row['id'] .'

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!

CodePudding user response:

PHP shorthand tag for echo is missing in href link.

This Code snippet should work:

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

CodePudding user response:

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

So like this:

href="read.php?id='. $row["id"] .'"
  •  Tags:  
  • php
  • Related