Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/312940-using-the-id-to-display-data/
Share on other sites

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.