php - sending href with parameter in a loop -
<!doctype html> <html> <head> <title>main page</title> </head> <?php session_start(); ?> <form action="new_question.php" method="post"> <input type="hidden" name="sid" value="<?php echo $_session['username']?>"> <input type="submit" value="new question"> </form> <?php include ("connection.php"); $result = mysqli_query($con,"select * question_table"); while($row = mysqli_fetch_array($result)) { echo "<a href=\"http://localhost/project/question.php\">" . $row['question'] . $row['q_id'] . "</a>"; echo "<br>"; } ?> <body> </body> </html>
i have 5 question in database each id. page prints them link in loop. upon clicking of link goes "question.php" file. there want echo question database clicked previously. problem in "question.php" file how find out link clicked among 5. should send parameter along link? how parameter change in each loop? how do in page? if send parameter link how receive in "question.php" file?
echo id parameter on anchor. can remove id anchor text since it's not needed there anymore.
while($row = mysqli_fetch_array($result)) { echo '<a href="http://localhost/project/question.php?id=' . $row['q_id'] . '">' . $row['question'] . '</a><br>'; }
and in question.php
$_get['id']
Comments
Post a Comment