Echo PHP

Ask about a PHP problem here.
Post Reply
Thunderbob
Posts: 46
Joined: Sat Jun 30, 2012 12:31 pm

Echo PHP

Post by Thunderbob »

SO on my site I have a navigation bar.
yourtechview.com

Now in the past I've had to manually change every single freaking link in the navigation bar on ALL 40 plus pages of my site.
As you can tell this becomes a very very strenuous process. I am now trying to store all of the navigation bar information inside a file called menu.php
I stored all of the html for the navigation bar into a variable called $nav1 . $nav1 is shown to users that are not logged in.
I stored all of the html for the navigation bar to be seen by a user that is logged into into $nav2.
$nav2 ='
<li>
     <a href="/index.php">Home</a>
<ul>
<li>
<a href="/home.php">Special Home Page</a>
</li>
</ul>
</li>
<li>
     <a href="/forum.php">Forums</a>
<ul>
				<li style="z-index:5;">
					<a href="/forum_section.php?sid=17">New Members</a>
									
				</li>
				<li style="z-index:5;">
					<a href="/forum_section.php?sid=19">General Chat</a>
			
				</li>

				<li>
					<a href="/forum_section.php?sid=38">Announcements</a>
								
				</li>
                    </ul>
</li>
<li>
     <a href="/lounge.php">Lounge</a>
<ul>
				<li style="z-index:5;">
					<a href="/photoroll.php">Memes & Rage Comics</a>
									
				</li>
				<li style="z-index:5;">
					<a href="/lounge.php">Video Blog</a>
			
				</li>

				<li>
					<a href="#">Games (coming soon)</a>
								
				</li>
				<li>
					<a href="#">Contests (coming soon)</a>				
						
				</li>
			</ul>
</li>
<li>
     <a href="/articles.php">Articles</a>
</li>
<li>
     <a href="/market.php">Market</a>
     <ul>
		<li style="z-index:5;">
			<a href="/market.php">Redeem Points</a>
									
		</li>
		<li style="z-index:5;">
			<a href="http://myworld.ebay.com/yourtechview/">YTV Store</a>
			
		</li>

		<li>
			<a href="/forum_section.php?sid=22">Sell Your Stuff</a>
								
		</li>
    </ul>
</li>
<li>
     <a href="/source/login.php">Login</a>
<ul><li><a href="/source/register.php">Register</a>
</ul>
</li>
</li>';
Here's the flow of the problem.

When you login to my site; the tab that says "Login" changes to the username of your account.
The problem is that I keep getting a blank space. $myusername is defined as the session username on both menu.php and my index test page. I basically want to echo a variable that contains php inside of it.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Echo PHP

Post by jacek »

Well if you do
$something = 'test';

echo "Something: {$something}";
it will print "Something: test", not sure if that answers. It might also be worth considering using a more complete template system, I did a video on a pretty simple one a while ago. This method you have at the moment will become pretty hard to work with.
Image
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: Echo PHP

Post by Helx »

Just do what I do with this,
Use SQL entries, then on each page query the items?

Then when your logged in, it works as if everything is static.
Plus lets not forget the possible administration abilities,
editing menus from an admin page :D
Post Reply