Jump to content

Dynamic links


Steve_Berry
 Share

Recommended Posts

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 &amp; 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; ?>

 

Link to comment
Share on other sites

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.

lower.png

Link to comment
Share on other sites

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.

 Share

×
×
  • 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.