User Tools

Site Tools


en:web_development:media:javascript

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
en:web_development:media:javascript [2022/06/01 16:17]
mag [PHP Variables]
en:web_development:media:javascript [2023/08/16 09:33] (current)
Line 150: Line 150:
   * Variables in PHP are always represented by <html>$</html>and the variable name.   * Variables in PHP are always represented by <html>$</html>and the variable name.
   * In this case, we have a variable named 'page' and we assign it the value of 'media' which is the page name.   * In this case, we have a variable named 'page' and we assign it the value of 'media' which is the page name.
-  * The code in 'header.php' acts as if it is the same page, so we can use our variable there too.+  * Add a command to display the variable. 
 + 
 +<code><?php 
 +    $page = "media"; 
 +    echo $page; 
 +    include("header.php"); 
 +    include("menu.php"); 
 +?></code> 
 + 
 +  * When you save, upload and run the code, you'll see the word 'media' at the top. 
 +  * The code in 'header.php' is part of the same page, so we can use our variable there too.
   * Now open 'header.php' and replace the <html><script></html> line with the following.   * Now open 'header.php' and replace the <html><script></html> line with the following.
 <code>    <script src="<?php echo $page; ?>.js"></script></code> <code>    <script src="<?php echo $page; ?>.js"></script></code>
en/web_development/media/javascript.1654125427.txt.gz · Last modified: 2023/08/16 09:33 (external edit)