php - Getting data based on which row chosen using session
882
How do I get the particular data(link url) depending on the row in which I pressed the button "edit" to be used on the edit.php page. As for now I'm using session but the only data( link url) I got is the "bing.com" although I pressed the button on the "google.com" row.
PHP
<?php
while ($rows = mysqli_fetch_array($result)){
$_SESSION["shorturl"]=$rows['shorturl];
?>
<tr>
<td><?php echo $rows['shorturl']; ?></td>
<td><?php echo $rows['phonenumber']?></td>
<td><button onclick="location.href = 'edit.php';">Edit</button><button onclick="location.href = 'show.php';">Show</button><button onclick="location.href = 'delete.php';">Delete</button></td>
</tr>
<?php }?>
Answer
Solution:
You can send record id as request parameter in your edit/show/delete. Make the changes in your code as Follow:
While fetching data in particular file, just check if
id
is set on that file. IfID
is set, then do your operations on recordID
which we have sent in request parameter.Note: Session will not work for your question as it holds data till session ends.
Answer
Solution:
You are overwriting the session-variable every time you run through the loop here:
Maybe u can try to use a GET-Param instead
Then retrive the shorturl on the edit.php site like this: