Displaying data using href by $_GET['id'];

After several attempts, I now have data displayed on my index.php page, but the data is from all rows. Luckily I have two rows. The page also has a menu - with two links.

What I would like help with is:

  1. How to display index.php with just the data for it - i.e. home page data.

  2. How to display data if either the ‘home’ or ‘copyright’ links are clicked.

I understand you can use $_GET{‘id’], and isset(), but I don’t know how to do that.

I include the full html page code:

<?php
// database connection
require_once('admin/databasecon.php');

?>
<!DOCTYPE html>
<html>

  <?php include 'includes/headsection.php'; ?>

  <body>

    <?php
    // displaying data
    $table = "pages";  // table
    $sqli = "SELECT * FROM $table ORDER BY id ASC";
    $result = $conn->query($sqli);
    ?>

    <!-- topMenu -->
    <table id="topMenu">

      <tr>
        <td><h1 class="siteName">Scarab Beetle</h1></td>

        <?php

        if ($result = mysqli_query($conn, $sqli)) {
          while($row = $result->fetch_assoc()) {
              echo  "<td class='navItem'>" . "<a href=index.php>" . $row["menuheader"] . "</a>" . "</td>";
          }
        }

        ?>
      </tr>

    </table>
    <!-- topMenu end -->

    <!-- timeline menu -->
     Menu goes here
    <!-- timeline menu end -->

    <!-- page title -->
    <?php

    if ($result = mysqli_query($conn, $sqli)) {
      while($row = $result->fetch_assoc()) {
          echo  "<h1 class='centered'>" . $row["pageheader"] . "</h1>";
      }
    }

    ?>

    <hr>

    <!-- page content -->
    <?php

    if ($result = mysqli_query($conn, $sqli)) {
      while($row = $result->fetch_assoc()) {
          echo  $row["pagetext"];
      }
    }

    ?>

    <hr>

    <div class="clear"></div>

    <!-- footer content -->
    <?php include 'includes/footersection.php'; ?>
    <!-- footer content end -->

  </body>

</html>

I understand I am asking for code, but I don’t have a clue what to do without it.

I thank you in advance you give me.

Well, Sherry, you show the same query being displayed three times. Also, since it is the same query, everything will be the same. Let’s find out what you are attempting to do.

Normally, a website has several pages. Each page feeds other pages. Sometimes you pass info to the other pages from the previous page. The “index” page or “index.php” page is used as a starting off point for the user to select what they want to do next. Therefore, you would normally have an index page, then other pages to handle various parts of your site. Seldom do you just have one page on a website.

Now, if you are attempting to use just one page and change the title, menus and content of that one page depending on buttons or links, it can be done but is how it is normally done. Let’s say your first index page is a log in page where members log in to their accounts. That would be just one page and dedicated to all the login code only. Once logged into your site, the user would be taken to another page something like a “home” page where they could see things that are only for them. Each page would feed another page. And, each page would be set up for one process each.

With all that said, you can use database tables to control just one page if you wanted to. It is not too complicated, but would require more work and be much harder to follow when changes are needed. If you want just one page, you can pass the data thru GET functions or SESSION functions. I prefer SESSION functions because they stay hidden from the user and makes it harder to hack. Either will work.

Now that I have explained a few options, what is your site for? What is the general plan or layout of what you want to accomplish? If you tell us that, we can suggest further help.

I noticed you have many includes in your code you posted. Normally, in a website, you would have many different pages to handle each user area. But, you would use the same header, menu and footer displays on every page. Such as this site you are viewing now. the header is the current post and your login info and then a horizontal rule with all the content after that. Seldom changes!

Give us more info and we can help!

Hello, thanks for the information. I want just one page to view the data. My site is to display historic information and each information will be a link. If you wish to see what I mean, I have a none - php site online [http://scarab-beetle.com/]. It is this site I want to redo as php - simply due to the amount of pages that I have, and will have should I continue with just HTML.

Interesting site! I think it can be converted to PHP and MySQLi database without a lot of trouble.
In this type of site, you would keep a new page for all the top menu items. ( Home, copyright, terms, etc.)
And, the data that is displayed would be dynamically loaded from the various menus. But, it will be a lot of work to set it up. Later on, this would make the site much easier for you to maintain as it grows.

Now, a few comments on how this process needs to go. Before you code anything at all, you would need to layout your plans in detail. First, you need to make a list of all your data and how you plan to index it. You need to somehow create a way to make it all easy to access in your database. This will be a long process overall as you will need to learn a lot to be able to do everything you want to. But, we are here to help you along your way. Here are some general comments on your current site and how to break it up to rewrite it in PHP and put the data into a database. These comments are to get you started thinking about the processes involved.

Your project will need three display parts. The header, content area and footer. The footer is super simple, just your copyright notice. Easy to put that into a footer.php file. The content will be the data displayed when a user selects something to read. The header section is more tricky. I should contain all the menus for all the pages. It should contain the < html> info and all of the menus all the way down to the gold horizontal menu. The gold menu will, of course, change depending on the other menus selected. One thing about the menu, I might move all the items except HOME to the footer. People who visit your site will not care about your terms/disclaimer/privacy at all. They might view them once and then never again. Therefore, you might want to make them smaller and put in the footer with your copyright notice. Just my humble opinion. And, if you do that, you can remove the home button and add some scarab beetle images next to your title to make it more fancy. On the terms/disclaimer/privacy pages, you can add a button that says “back-to-homepage” or something like that. Just my opinion.

Now, with all that said, you probably should handle the menus first. You need to list them and decide how you want them stored in your database. You have three levels of menus. First one is a title such as “Timeline”. You might want to change this so that when a user selects a sub-menu such as 8th-Dynasty, that title would be in the title area. That way, the user can see where they are at any one moment. Again, just my opinion. Next you have the real menu’s which are the year-spans. Each of these will be needed to be listed and saved in the database. And, finally, you will need the sub-menus with all the items that go under the year menus. You will need to list these and store them in your database. Once all of these are stored, you would then need to create PHP code to “populate” the various HTML code with the menus.

This brings me to another issue. You can alter the menus manually by editing the database itself, but, you might want to create an ADMIN panel that would allow you to edit them from a webpage instead of having to do it in the database manually. This would add a lot more code, but, would make your life much easier later on.

Well, then, you need to store all of your content along with links to other pages such as references and things like that. Another big step.

I have probably overstepped what you were asking for, but, wanted you to understand what you are in for. It is not as hard as it sounds. Just a different way to program a webpage. Anyone can learn this! Not hard, just a lot to learn. We are hear to help. If you need to send a private message about this, you can click on my initial “E” and click on message and send me one. But, you can just ask questions here and everyone on the site can jump and and learn with you or teach you, too. Everyone here are very helpful and you will learn a lot! Good luck and let us know when you have more questions…

1 Like

Why have you now gone back to using the msyqli extension, which is where you were at in February/March of last year? In your most recent thread on this forum for this task (11/12 days ago) - Uncaught PDOException: SQLSTATE[42000] , you were using the PDO extension and a prepared query.

When we see that you are throwing away advances you have made from one post to the next, it says that you are not really learning anything by doing this. There’s (at least) two problems with this random try it and throw it away approach - 1) it will take you a really long time, approaching infinity, to accomplish a task, because you are not building on what you have done before, and 2) those who have taken the time to read through what you are doing are going to be less likely to waste time on code that keeps changing for no reason. Programming is a deliberate, intentional activity. You must have a stateable reason for each change you make to code.

Hi - I was trying to find out how to do what I wanted and was getting nowhere, so I tried a different way to do it, and still got nowhere. However, I will take you advice and stick to PDO extension and a prepared query. The last thins I want to do it waste peoples time.

Yes, PDO is better than MySQLi ! More secure and actually easy to use once you try it.

But, this point is minor compared to your wanting to create a new system. Did you have any questions on all those notes I started you off with? If so, let us know.

At the moment I am following your suggestions on separating the page into three parts. I have moved the links to the footer and removed the home page. Once I have finished this, I will decide on how I want the data displayed - i.e. static for the footer or dynamic. The rest will, hopefully be dynamic.

Sponsor our Newsletter | Privacy Policy | Terms of Service