Html <a> link with variable

时间:2018-05-24 21:05:09

标签: php html mysql phpmyadmin

I'm trying to do something like this:

 <?php while($row = mysqli_fetch_assoc($result)) { ?>

    <li><?php echo $row["msg"] ;?>(id: <?php echo $row["msg_id"] ;?>) | sent at <?php echo $row["data"] ;?> <a href="message.php">see</a> | <a href="delete.php?msg_id=<?php $row["msg_id"]?>">delete</a></li>

 <?php 

    }
 ?>

but it doesn't work. The msg_id is correctly and the db informations are good, but i don't know how to make the url like delete.php?msg_id= $ROW_MSG_ID. Maybe you could help me. Thanks!

1 个答案:

答案 0 :(得分:0)

<?php
/* This code is a little bit hard to read.  
It would be much easier to troubleshoot if it is cleaner.  
Besides that, the problem could be your message.php or delete.php.  
This code is actually fine by itself. */?>


<li>
    <?php
        echo $row['msg'].'(id: '.$row['msg_id'].') | sent at '.$row['data'];
        echo '<a href="message.php">see</a> | '.
             '<a href="delete.php?msg_id='.$row['msg_id'].'">delete</a>';

    ?>

</li>

<?php
/* Output:
       * message(id: message_id) | sent at row_data see | delete.


// [link]see[/link to message.php] | [link]delete[/link to delete.php]

*/?>