Steve_Berry Posted June 18, 2021 Share Posted June 18, 2021 Hello. What I have created is a menu with links. The links will display content on the page from a database. I have the links with id displayed, but nothing is displayed when the link is clicks. I have seen isset() and $_GET used but not a form and I don't know how to change the code to allow the display of data using ID. My site is local, and I am using XAMPP. The database connections work. This is my code: // query $query = "SELECT * FROM topmenu ORDER BY id ASC"; $row = $PDO->query($query); .... <table class="topmenu"> <tr> <td> <h1 class="siteName">site title</h1> </td> <?php foreach($row as $data) { ?> <td><a href="index.php?id=<?php echo $data['id']; ?>"> <?php echo $data['menuheader']; ?> </a></td> <?php } ?> </tr> </table> As a beginner, I would appreciate any help, no criticism of my code please! Also, is there a way of hiding the id in the url? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/312940-using-the-id-to-display-data/ Share on other sites More sharing options...
gw1500se Posted June 18, 2021 Share Posted June 18, 2021 <a href="\"index.php?id=".<?php echo $data['id']; ?>."\">" 1 Quote Link to comment https://forums.phpfreaks.com/topic/312940-using-the-id-to-display-data/#findComment-1587351 Share on other sites More sharing options...
Barand Posted June 18, 2021 Share Posted June 18, 2021 15 minutes ago, Steve_Berry said: no criticism of my code please! As any suggested changes could be inferred to be criticisms of your code, you have effectively gagged us and painted yourself into a corner as far as getting help is concerned. Also, and this is a criticism of the post, not the code, you have told us or shown us what you are trying to do when a link is clicked. Quote Link to comment https://forums.phpfreaks.com/topic/312940-using-the-id-to-display-data/#findComment-1587352 Share on other sites More sharing options...
cyberRobot Posted June 18, 2021 Share Posted June 18, 2021 When clicking one of the links, does the URL show the correct ID? If so, then the provided code is working fine. As Barand mentioned, we would need to see the code that processes the clicked ID to display the page. 2 hours ago, Steve_Berry said: Also, is there a way of hiding the id in the url? Hiding the ID from the URL will prevent people from doing things like bookmarking (or linking) to the pages being generated by the script. So I wouldn't recommend going this route. Quote Link to comment https://forums.phpfreaks.com/topic/312940-using-the-id-to-display-data/#findComment-1587361 Share on other sites More sharing options...
Steve_Berry Posted June 21, 2021 Author Share Posted June 21, 2021 Hello, I meant no disrespect when I asked for no criticism of my code, what I meant was no negative remarks. In other forums, my code as been 'incorrect', 'bad', etc, when all I had done was use examples found online that parts of I did or could not use since I had no idea what went wrong or how to fix it. I discovered what I meant my hiding the id - I think it's called clean urls. I do appreciate your help and hope no offence was taken. Quote Link to comment https://forums.phpfreaks.com/topic/312940-using-the-id-to-display-data/#findComment-1587420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.