Steve_Berry Posted July 3, 2021 Share Posted July 3, 2021 This is a question about dynamic links. At the moment I have a dynamic page from a table, I'll call it tableA. The links all work fine, so when clicked, information is displayed from the table. The issue will be when I come to create a new table entry. This new pages (or entry), will itself contain a link to other information. Assuming I have the required information in tableA, how do I activate a dynamic link from within a page that itself dynamically produced? I use PDO for the link to the database, and the page that shows the text uses a form, with buttons to allow the user to select a menu item. The php: <?php // Connect to the databaase $PDO = new PDO("mysql:host=****;dbname=****", "****", "****"); // set the PDO error mode to exception $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set up defaults $current_title = ""; $current_page_data = ""; // Check if the user posted the page if($_SERVER['REQUEST_METHOD'] == 'POST') { // Check if user pressed a menu button if(isset($_POST["menu"])) { // User has selected a menu, meaning a page was selected, now load the page $current_title = filter_input(INPUT_POST, "menu"); // Now get current data from the database, if the page was never created, add it to the database $stmt = $PDO->prepare("SELECT * FROM pages WHERE pageheader=?"); $stmt->execute([$current_title]); $row = $stmt->fetch(); if($row) { // Page is in the databaswe already, load the text for it if(isset($row["pagetext"]) AND trim($row["pagetext"])!="") { $current_page_data = $row["pagetext"]; } } else { // Page was never created, add it with blank text $current_page_data = "This page is under contruction!<br><br>Please check back again later!"; } } } ?> The form (partial): <form name="****form" method="post" action="#"> <table id="timeline"> <tr> <td id="contentMenu"> <span class="item"> <div class="dropdown"> <button class="dropdownButton">Pre 3150 BC</button> <div class="dropdownContent"> <button name="menu" type="submit" value="Predynastic Egypt">Predynastic Egypt</button> <button name="menu" name="menu" value="Lower Egypt">Lower Egypt</button> <button name="menu" type="submit" value="Upper Egypt">Upper Egypt</button> <button name="menu" type="submit" value="Upper and Lower Egypt">Upper & Lower Egypt</button> </div> </span> .... </td> </tr> </table> </form> <!-- page content --> <hr> <h1 class="center"><?php echo $current_title; ?></h1> <hr> <?php echo $current_page_data; ?> Quote Link to comment https://forums.phpfreaks.com/topic/313038-dynamic-links/ Share on other sites More sharing options...
gw1500se Posted July 3, 2021 Share Posted July 3, 2021 Not sure I understand the question but it sounds like you need to use JavaScript/Ajax on the new page. That code would itself be static but the result would be dynamic. Quote Link to comment https://forums.phpfreaks.com/topic/313038-dynamic-links/#findComment-1587805 Share on other sites More sharing options...
requinix Posted July 3, 2021 Share Posted July 3, 2021 I can see that your list of menu buttons isn't dynamic and it should be, which will also fix that one bug and make sure it doesn't happen again. Otherwise I can't tell what you're asking about either. Quote Link to comment https://forums.phpfreaks.com/topic/313038-dynamic-links/#findComment-1587825 Share on other sites More sharing options...
Steve_Berry Posted July 4, 2021 Author Share Posted July 4, 2021 Thanks for the response. I apologise as I did not make it clear enough about what I would like to happen. There are no issues with how the form produces data on the page. It may not be dynamic but the links work - data is inserted depending on which button is placed. What I need help with relates to the inserted pages. For example. The button named Lowe Egypt, will show text and images from the database. However, the page will contain information of rulers at the time so Ruler1, Ruler2 etc, will be a link. So, essentially, a link that is itself in a data table, ideally the same one as the page that is displaying the link. I have included a link that better explains what I mean. The Lower Egypt information would be a menu selection, as you know, and you can see the list of rulers I mentioned. Once clicked the information would be shown in the same page as Lower Egypt was - replacing it obviously. My skills or lack of, prevent me from setting up the Lower Egypt page with dynamic links. Is it possible to use <a href="timeline.php?id=( some number ) within the same code as the Lower Egypt text? As a test, I use this: <a href="#">a link to ruler</a>, which displays as a link. How do I: add to the php on the timeline php to have this link working. create a different Select from etc to have this link working. At the moment the text for the links does not exist. I need to know how to Select it first. Ideally I would like to use <a href="timeline.php?id">, but if the link refers to a different page (or needs to) say - rulers.php?id, than that would be fine. i would be grateful, If you can provide help with the code to do any of this. Quote Link to comment https://forums.phpfreaks.com/topic/313038-dynamic-links/#findComment-1587831 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.