Jump to content
xisto Community
KansukeKojima

Php Linking One of the major advantages of PHP is the ability to create something

Recommended Posts

PHP Links

Requirements

1. You should understand the majority of PHP (ex: variables, echo, etc. http://www.w3schools.com/ is a good reference).

2. Experienced with HTML.

3. You need a PHP compatible server if you wish to see your results.

 

Description

One of the major advantages of PHP is the ability to create something similar to an Iframe, only without the scroll-bar. The main advantage of this is that you only need one layout page, while the others can be simple 'white space & content' pages. Another advantage of this is your web site doesn't look like a fifth grader coded it.

 

Try It Out

The Code

 

<?php $default = "blah.html"; if($id == ""){$id = $default;}elseif(isset($id)){$id = $id;} ?><?php include ("$id"); ?>
Alright, so now your asking, "What the fudge!?" I'll explain it to you.

 

The $default variable is the default page that will appear when a visitor comes to your site. The Replace blah.html with the location of your default or main page. Now when somebody visits your site they will see that page.

 

See that include tag? This tells your server to include whatever $id is equal to. The tag above it makes $id equal to whatever you file you chose for $default. So how do we create a link? We simply change what $id is equal to using some everyday HTML - with a twist.

 

The Code

 

<a href="?id=blah2.html">Link Text</a>
See the twist? Using ?id=blah2.html we are able to change what $id is equal to. Replace blah2.html with whatever page you want to create a link.

 

Get it? If not then try reading it over a few times.

Share this post


Link to post
Share on other sites

Question on your code

 

Php Linking

 

 

 

I'm a newbie to php, so forgive me for the ignorant questions I might have for you!

 

I'm trying to create your PHP link code:

<?php $default = "blah.Html"; if($id == ""){$id = $default;}elseif(isset($id)){$id = $id;} ?><?php include ("$id"); ?>With mine:<?php $default = "venue.Php"; if($club_id == " "){$club_id = $default;}elseif(isset($club_id)){$club_id = $club_id;} ?><?php include ("$club_id"); ?><a href="?id=blah.Html">Venue 1</a>

Is there supposed to be something in the if($club_id == " ") ???? I can't get the link to blah.Html to open (I did create blah.Html)

 

Any help would be appreciated!

Jviney

 

-question by jviney

Share this post


Link to post
Share on other sites

This is yours;

<?php $default = "blah.html"; if($id == ""){$id = $default;}elseif(isset($id)){$id = $id;} ?><?php include ("$id"); ?>
What about this?

<?php $default = "blah.html"; if(!$id){$id = $default;} ?><?php include ("$id"); ?>

Changes:

if(!$id) checks if $id is 0 or "" or null and there is no need of elseif(isset($id)){$id = $id;}

Edited by Erdemir (see edit history)

Share this post


Link to post
Share on other sites

Hey trap I suggest you to use method empty() if you would like to check whether variable is in fact empty. Because the code that you have pulled out:

 

if($id == ""){$id = $default;}elseif(isset($id)){$id = $id;}

in fact check if there is something in there that is equal to "" but if you haven't initialized variable $id then it will return always false. This is common mistake for the beginners with PHP.

 

So instead of: $id == "" you should put in empty($id)

 

tell me if this works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.