I have a couple of links in a unordered list. When the user click a link, some text should be displayed on the same page as the link.
Now, this works:
<a href=my_page.php?var1=Hello!>Hello again!</a>
But I want the link to display text contained in a variable. Something like this:
<?php
$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse et tempus risus. Mauris adipiscing consequat odio, eleifend lobortis velit hendrerit sit amet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eu lectus in elit tempor porttitor at eu mi. In ullamcorper semper rhoncus. Quisque id varius dolor. Morbi congue luctus rhoncus. Sed scelerisque posuere vulputate. Nullam at libero turpis, non bibendum odio. Nulla facilisi. Morbi hendrerit nulla eget metus varius in aliquam tortor mattis. Nullam faucibus massa a ligula dictum id commodo metus convallis. Phasellus orci est, malesuada a varius sed, congue at dolor. ';
$text = $_GET[“$text”];
echo “$text”;
?>
<a href=my_page.php?$text>Link number 1</a>
Of course this does not work. What am I doing wrong? All help appreciated!
Anything after a ? in a URL string is passed as variables (In PHP, those variables are stored in the $_GET superglobal array).
== is not technically the same as === ; Because of typing, 0 == false is a true comparison, but 0 === false is not, because the types are different (Int vs Boolean)
As for “This script gives you a list like click click click”… compare it with this:
Follow the variable, and read up on arrays in the manual.
Say you had some links oin a page:
<a href =“linktest.php?message=mymessage”>mymessage</a>
<a href =“linktest.php?message=myothermessage”>myothermessage</a> linktest.php
<?php
echo 'message from previous page was : '$_GET['message'] ;
$messages = array(
'mymessage' => "this is a message" ,
'myothermessage' => "this is another message"
);
// check what is in your array
var_dump ( $messages );
// assign a variable to the chosen array key
$message = $messages[$_GET['message']];
echo $message ;
?>
Thanks! Does php have something comparable to target in html? I got a php-page. Header, navigation and footer are included files. Can I do the following:
when I click a link in the navigation, the information in the content area is supposed to be updated. I guess it means that I have to dynamically load a php page into the conte area using include.
I now have working links. But how do one solve this problem? Let’s say my content area shows content.php because I am using <?php include(“content.php”);?>
Now: If I click a link in the nav area, I want to substitue that content.php with another php file. I have been doing some experimenting but if I include another file into the content area, the content.php will show both php files instead of the file that my link points to.