PHP problem

Her kan du få hjælp og stille spørgsmål til PHP!
Besvar
Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24
PHP problem

Indlæg af Crow » 9. maj 2014, 14:12

Greeting's
i hope someone could lend me a hand and point out why i cannot include my navigation bar within "<php?" "?>", i can easily set them up later but i would like to include the navigation bar so i can use php to add information to the field's.

Kode: Vælg alt

<!DOCTYPE html>
<html>
<head>
<title>website test/example</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="tinydropdown.css" type="text/css" />
<script type="text/javascript" src="tinydropdown.js"></script>
<body>  

<div class="nav">
    <ul id="menu" class="menu">
        <li class="nodiv"><a href="index.php">Home</a></li>
        <li><a href="#">One</a>
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li class="submenu">
                    <a href="#">Three</a>
                    <ul>
                        <li class="noborder"><a href="#">One</a></li>
                        <li><a href="#">Two</a></li>
                        <li><a href="#">Three</a></li>
                    </ul>
                </li>      
            </ul>
        </li>
        <li><span>Two</span>
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
                <li class="submenu">
					<span>No Link</span><ul>
                		<li class="noborder"><a href="#">One</a></li>
                		<li><a href="#">Two</a></li>
                		<li><a href="#">Three</a></li>
                		<li><a href="#">Four</a></li>
                		<li><a href="#">Five</a></li>
                                
					</ul>
				</li>
                <li><a href="#">Five</a></li>
                <li><a href="#">Six</a></li>
            </ul>
        </li>
        <li><a href="#">Job</a>
            <ul>
                <li><a href="#">CV</a></li>
                <li class="submenu">
					<span>Div.</span><ul>
                		<li class="noborder"><a href="#">Eksam's</a></li>
                		<li><a href="#">Certification's</a></li>
                		
                		<li><a href="#">Four</a></li>
                		<li><a href="#">Five</a></li>
					</ul>
				</li>
                <li class="submenu">
					<span>Job Activity</span><ul>
                		<li><a href="http://google.com">Test1</a>
                                    <ul id="info">
                                        <li><p>00-00-0000 -> 00-00-0000</p>
                                        </li></ul>
                                <li><a href="#">Test2</a>
                                    <ul id="info">
                                        <li><p>00-00-0000 -> 00-00-0000</p>
                                        </li></ul>
                                <li><a href="http://google.com">Test3</a>
                                    <ul id="info">
                                        <li><p>00-00-0000 -> 00-00-0000</p>
                                        </li></ul>
                                    </ul>
            <li class="submenu">
					<span>Hobby/Interrest's</span><ul>
                		<li><a href="#">Current</a>
                                    <ul id="info">
                                        <li><p>This website is part of my current interrest</p>
                                        </li></ul>
                                <li><a href="#">Planned</a>
                                    <ul id="info">
                                        <li><p>test.</p>
                                        </li></ul>                                
            </ul>
            </ul>
        </li>
        <li><a href="info.php">Info</a>
            <ul id="info">
				<li>
                	<p>this website is written in jscript, PHP CSS & html5 from scratch without the usage of CMS systems.</p>
				</li>
            </ul>
        </li>
    </ul>
</div>
<script type="text/javascript">
var dropdown=new TINY.dropdown.init("dropdown", {id:'menu', active:'menuhover'});
</script>

<div id="menubar">
    <p>this is the menu bar</p>
    
</div>


<div id="content">
<p> this is just simple content</p>
</div>

<footer>
    footer
</footer>

</body>  
</html>

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 10. maj 2014, 21:27

I dont see <php? anywhere in your code.

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 12:47

i took it out since if i place it from the start of <body> to </body> as i would like to then it causes an issue that i cant figure out, however if i limit it from before the <div> tag or after the </div> tag i accept's it without error's but i would like to implement php code in between the div tag's in order to manage thenavigationbar better etc. but right now i am searching blindly from top to end without knowing what causes it or if i simply cannot use div tag's alongside php :/

i would really appreciate some help since i don't want to use CMS program's before i master or learn how to do it without :)

this is how i would like to place the tag's:

Kode: Vælg alt

<!DOCTYPE html>
<html>
<head>
<title>website test/example</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="tinydropdown.css" type="text/css" />
<script type="text/javascript" src="tinydropdown.js"></script>
<body> 
<?php
<div class="nav">
<ul id="menu" class="menu">
<li class="nodiv"><a href="index.php">Home</a></li>
<li><a href="#">One</a>
<ul>
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li class="submenu">
<a href="#">Three</a>
<ul>
<li class="noborder"><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
</ul>
</li> 
</ul>
</li>
<li><span>Two</span>
<ul>
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
<li class="submenu">
<span>No Link</span><ul>
<li class="noborder"><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
<li><a href="#">Four</a></li>
<li><a href="#">Five</a></li>

</ul>
</li>
<li><a href="#">Five</a></li>
<li><a href="#">Six</a></li>
</ul>
</li>
<li><a href="#">Job</a>
<ul>
<li><a href="#">CV</a></li>
<li class="submenu">
<span>Div.</span><ul>
<li class="noborder"><a href="#">Eksam's</a></li>
<li><a href="#">Certification's</a></li>

<li><a href="#">Four</a></li>
<li><a href="#">Five</a></li>
</ul>
</li>
<li class="submenu">
<span>Job Activity</span><ul>
<li><a href="http://google.com">Test1</a>
<ul id="info">
<li><p>00-00-0000 -> 00-00-0000</p>
</li></ul>
<li><a href="#">Test2</a>
<ul id="info">
<li><p>00-00-0000 -> 00-00-0000</p>
</li></ul>
<li><a href="http://google.com">Test3</a>
<ul id="info">
<li><p>00-00-0000 -> 00-00-0000</p>
</li></ul>
</ul>
<li class="submenu">
<span>Hobby/Interrest's</span><ul>
<li><a href="#">Current</a>
<ul id="info">
<li><p>This website is part of my current interrest</p>
</li></ul>
<li><a href="#">Planned</a>
<ul id="info">
<li><p>test.</p>
</li></ul> 
</ul>
</ul>
</li>
<li><a href="info.php">Info</a>
<ul id="info">
<li>
<p>this website is written in jscript, PHP CSS & html5 from scratch without the usage of CMS systems.</p>
</li>
</ul>
</li>
</ul>
</div>
<script type="text/javascript">
var dropdown=new TINY.dropdown.init("dropdown", {id:'menu', active:'menuhover'});
</script>

<div id="menubar">
<p>this is the menu bar</p>

</div>


<div id="content">
<p> this is just simple content</p>
</div>

<footer>
footer
</footer>
?>
</body> 
</html>

cristian
Moderator
Moderator
Indlæg:882
Tilmeldt:26. sep 2011, 21:31
Kontakt:

Re: PHP problem

Indlæg af cristian » 11. maj 2014, 14:03

Please put your code inside code snippets. Makes it easier to read.

Kind regards.

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 11. maj 2014, 14:57

Your using the PHP delimiters <?php ?> in the wrong way.

PHP code goes inside <?php and ?>.

Heres an example.

Kode: Vælg alt

<body>

<?php

    echo 'helleo from PHP';

?>

<div>this is HTML</div>

<div><?php echo 'this is PHP'; ?></div>

Kode: Vælg alt

<!DOCTYPE html>

<html>

   <head>
      <meta charset="utf-8">
      <title>Hello world</title>
   </head>

   <body>
      <?php echo "<div>Hello world</div>\r\n"; ?>
   </body>

</html>

Kode: Vælg alt

<?php

echo "<!DOCTYPE html>\r\n";
echo "\r\n";
echo "<html>\r\n";
echo "\r\n";
echo "   <head>\r\n";
echo "      <meta charset=\"utf-8\">\r\n";
echo "      <title>Hello world</title>\r\n";
echo "   </head>\r\n";
echo "\r\n";
echo "   <body>\r\n";
echo "      <div>Hello world</div>\r\n";
echo "   </body>\r\n";
echo "\r\n";
echo "</html>\r\n";

?>

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 15:12

in other word's i shouldnt try to encase the "div" tag's but place the <php? ?> within them ? like in the example shown below ?

i tried but it wont recognize the "?" in <php? or "?>" for some reason it only recognize's "<php" i am using netbeans IDE 8.0

Kode: Vælg alt

<!DOCTYPE html>
<html>
<head>
<title>website test/example</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="tinydropdown.css" type="text/css" />
<script type="text/javascript" src="tinydropdown.js"></script>
<body>  

<div class="nav">

<?php

    <ul id="menu" class="menu">
        <li class="nodiv"><a href="index.php">Home</a></li>
        <li><a href="#">One</a>
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li class="submenu">
                    <a href="#">Three</a>
                    <ul>
                        <li class="noborder"><a href="#">One</a></li>
                        <li><a href="#">Two</a></li>
                        <li><a href="#">Three</a></li>
                    </ul>
                </li>      
            </ul>
        </li>
        <li><span>Two</span>
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li><a href="#">Three</a></li>
                <li class="submenu">
               <span>No Link</span><ul>
                      <li class="noborder"><a href="#">One</a></li>
                      <li><a href="#">Two</a></li>
                      <li><a href="#">Three</a></li>
                      <li><a href="#">Four</a></li>
                      <li><a href="#">Five</a></li>
                                
               </ul>
            </li>
                <li><a href="#">Five</a></li>
                <li><a href="#">Six</a></li>
            </ul>
        </li>
        <li><a href="#">Job</a>
            <ul>
                <li><a href="#">CV</a></li>
                <li class="submenu">
               <span>Div.</span><ul>
                      <li class="noborder"><a href="#">Eksam's</a></li>
                      <li><a href="#">Certification's</a></li>
                      
                      <li><a href="#">Four</a></li>
                      <li><a href="#">Five</a></li>
               </ul>
            </li>
                <li class="submenu">
               <span>Job Activity</span><ul>
                      <li><a href="http://google.com">Test1</a>
                                    <ul id="info">
                                        <li><p>00-00-0000 -> 00-00-0000</p>
                                        </li></ul>
                                <li><a href="#">Test2</a>
                                    <ul id="info">
                                        <li><p>00-00-0000 -> 00-00-0000</p>
                                        </li></ul>
                                <li><a href="http://google.com">Test3</a>
                                    <ul id="info">
                                        <li><p>00-00-0000 -> 00-00-0000</p>
                                        </li></ul>
                                    </ul>
            <li class="submenu">
               <span>Hobby/Interrest's</span><ul>
                      <li><a href="#">Current</a>
                                    <ul id="info">
                                        <li><p>This website is part of my current interrest</p>
                                        </li></ul>
                                <li><a href="#">Planned</a>
                                    <ul id="info">
                                        <li><p>test.</p>
                                        </li></ul>                                
            </ul>
            </ul>
        </li>
        <li><a href="info.php">Info</a>
            <ul id="info">
            <li>
                   <p>this website is written in jscript, PHP CSS & html5 from scratch without the usage of CMS systems.</p>
            </li>
            </ul>
        </li>
    </ul>
</div>
<script type="text/javascript">
var dropdown=new TINY.dropdown.init("dropdown", {id:'menu', active:'menuhover'});
</script>

<div id="menubar">
    <p>this is the menu bar</p>

?>
    
</div>


<div id="content">
<p> this is just simple content</p>
</div>

<footer>
    footer
</footer>

</body>  
</html>

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 11. maj 2014, 15:42

This is not PHP code.

Kode: Vælg alt

    <ul id="menu" class="menu">
        <li class="nodiv"><a href="index.php">Home</a></li>
        <li><a href="#">One</a>
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#">Two</a></li>
                <li class="submenu">
                    <a href="#">Three</a>
                    <ul>
                        <li class="noborder"><a href="#">One</a></li>
                        <li><a href="#">Two</a></li>
                        <li><a href="#">Three</a></li>
                    </ul>
                </li>     
            </ul>
.............
.............
.............
            </li>
            </ul>
        </li>
    </ul>
</div>
<script type="text/javascript">
var dropdown=new TINY.dropdown.init("dropdown", {id:'menu', active:'menuhover'});
</script>

<div id="menubar">
    <p>this is the menu bar</p>

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 17:08

but is it not possible to use php code in the "href" ? for example when linking to the same page from multiple spot's in order to make it simpler to overlook, or if i need the same string of text multiple times ?

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 11. maj 2014, 17:36

Example.

Kode: Vælg alt

<a href="<?php echo $_SERVER["SCRIPT_FILENAME"]; ?>">Link</a>
You can do whatever you like.
So far you have zero PHP code in what you have written.

Try writing some PHP between <?php and ?>.

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 17:54

so would a line like this work if implemented ?

Kode: Vælg alt

<a href="<php? echo = $_SERVER;" ?>test</a>

<?php $_SERVER = "http://www.google.com" ?>

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 11. maj 2014, 18:18

No but you could do this.

Kode: Vælg alt

<?php
    $url = 'http://example.com';
?>

<a href="<?php echo $example; ?>">Link</a>

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 18:31

nice thank's you really helped me through that misunderstanding and in how to use php :D

i am just wondering why you store the address in $url and echo from $example

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 11. maj 2014, 19:48

My mistanke. Should have been $url both places.

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 19:49

thanks :)
i understand php a little better now thanks to your advice :D

Brugeravatar
scootergrisen
Moderator
Moderator
Indlæg:709
Tilmeldt:21. jun 2012, 23:40
Kontakt:

Re: PHP problem

Indlæg af scootergrisen » 11. maj 2014, 20:12

If your trying to make a menu and have the same menu on all your pages you can have you menu in one file.
And then use require_once 'menu.php'; to include the menu on all the pages.

Kode: Vælg alt

<!DOCTYPE html>
<html>
<head>
<title>website test/example</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="tinydropdown.css" type="text/css" />
<script type="text/javascript" src="tinydropdown.js"></script>
<body> 

<div class="nav">

<?php require_once 'menu.php'; ?>

</div>


<div id="content">
<p> this is just simple content</p>
</div>

<footer>
    footer
</footer>

</body> 
</html>
That way when you want to change the menu you only have to change it in one file.

Crow
Rutineret
Rutineret
Indlæg:64
Tilmeldt:15. apr 2014, 11:24

Re: PHP problem

Indlæg af Crow » 11. maj 2014, 20:18

thanks a ton :)

Besvar