Jump to content

[SOLVED] HTML links as PHP variables


chiching72

Recommended Posts

I am trying to make a navigation on my HTML page, where there is a list of links for lessons... example, lesson1, lesson2, etc.

 

I want to click on the link which would lead to a PHP page inside my HTML table, and give the PHP a variable, such as for lesson1, it would be "lesson1.cml", so that it knew it for was for lesson1. How do I accomplish This?

 

I am sorry if I am not too clear, I am desperate for any help tho, thanks!~

Link to comment
https://forums.phpfreaks.com/topic/39554-solved-html-links-as-php-variables/
Share on other sites

I am not sure if this is what you are asking but to pass variables from links to php you need to send them in the URL of link. This can be accomplished by:

 

<a href="http://lessons.php?selected_lesson=lesson1.cml">Lesson1</a>

<a href="http://lessons.php?selected_lesson=lesson2.cml">Lesson2</a>

<a href="http://lessons.php?selected_lesson=lesson3.cml">Lesson3</a>

 

Thus after the file name you put a '?' and then add a variable name put an '=' and then the value of the variable.

 

Now on the php page that is lesson.php in this case you can retrieve the value of which lesson was clicked. use

$selected_lesson = $_GET['selected_lesson'];

 

And there you have it. $selected_lesson now holds the lesson user clicked on.

Archived

This topic is now archived and is closed to further replies.

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