PDA

View Full Version : Php Links



splintercell!
26-02-2005, 02:05 PM
Before the old forum was cleared there was a thread explaining how to change content in a Text box without having to change the WHOLE page! Here is where I insert my main content using this code:

<?PHP
include("home.php");
?>

so... how do I change this content so new stuff will appear. Abit like with an iframe <a href=home.php target=main> how do i do it? :S

Sketti
26-02-2005, 02:09 PM
<a target="I1" href="PAGE NAME HERE">TEXT HERE</a>
The I1 is short for iFrame 1. same if you had 3 iFrames. There would be I1 - which would be the first one you put in. I2 - which would be the second one you put in. And I3 - which, obviously, would be the 3rd one you put in. Hope this helps. :)

Mentor
26-02-2005, 02:33 PM
oh this is quite easy.

What you want to do is dinamicly chnage the contents of a sites, via php.

basicly you just use the if statemnt


<?php

if($go=="linkname")
{
include("linkname.php");
}
elseif($go=="linkname2")
{
include("linkname2.php");
}
else
{
include("home.php");
}
?>
The set up links to say. if the page is index.php

index.php?go=pagename

<a href="index.php?go=pagename">link </a>

and if page name is equle to one of the else if statements it will include that page. If its not it will incude the page after the else.

just ad else if statmnts, after the firest else if to add more links.

hope that helps

splintercell!
26-02-2005, 02:43 PM
OMG! Thank you so much I was about to give up as I have been asking all day Thanks :D Ive given some rep

-JT-
26-02-2005, 10:41 PM
lol, this stuff is beyond me :(

splintercell!
26-02-2005, 10:45 PM
I dont understand it :D But it works

Mentor
26-02-2005, 11:27 PM
its quite simple realy



<?php

invokes php, aka gets it to prosses wahts inside the tag



if($go=="linkname")
{
include("linkname.php");
}

Then teh if fucntion comes in to play/

$go

is a varibale, and in this case is set by the url aka index.php?go=linkname

basicly means go is equal to link name.

now the if function comes along and IF linkname is equal to is equal to linkname, then it does what evers inbetween teh {} tags

If its not it ignos that part and moves on to the elseif

which works exsactly the same as the if, exspt its in the same function, and you can add as many as you wnat of them


elseif($go=="linkname2")
{
include("linkname2.php");
}


then the last part of the script is the Else option, which means if the varible is equl to none of the if or elseif statemnts, it will print this


else
{
include("home.php");
}


then the ?> tag simply tell it to stop invoking php



?>


simple huh?


edit:

And the bit i fogot to mention. The include tag simply gets all the data from the page its incling and dumps it in to the one tahst incluing it

-JT-
27-02-2005, 06:48 PM
so the "if($go=="linkname")
{
include("linkname.php");
}"

Will turn out as hyper links? What is the actual point in doing this? I just dont understand :@

iRoss
27-02-2005, 07:32 PM
yer lol just use html foo's :P why make it complicated!!!

splintercell!
27-02-2005, 07:40 PM
Cos I dont like iframes and this script makes it look alot nices Thanks mentor :) and the
"if($go=="linkname")
{
include("linkname.php");
}"
dosent make a link :P

iRoss
27-02-2005, 07:59 PM
but iframe are so easy, why dont u like them?

-JT-
27-02-2005, 08:09 PM
i am so confuzed :'(

Mentor
27-02-2005, 08:18 PM
If you use ifraims you cant link to a certain page, and keep the layout around it, aslo you cant make an ifraim fit to a dinaic contents size, this way builds the html direcvtly in to the page.

to make links you just use the normal html

<a href="index.php?go=page">bla</a>

The red bit is what sets the varible go

The p[hp then asks, if that go is set to anything, if its set to say page then it includes what ever page you may have wanted

-JT-
27-02-2005, 09:40 PM
so it puts a page on a page...?

Mentor
27-02-2005, 10:14 PM
sort of.

say i have
page.htm


<b> navigtion</b>
<br>
*imagnie lots of links are here*


rather than rewrite these links for each page.

ic an just on each page


<?php
include 'page.htm' ;
?>


wich will then

write all the html in page.htm in to the page u put the include in.

wich is how i do my navigtion, and how i do the outside of my page.

ratehr than rewrite it for each one.

this way say with cutenews if i dont have much news the bit will be short, if i do it will be long. rather than u having to put an exstar biig ifram where u dont need it.. or go in to scroll bars.

it litraly put the contents of the page it inludes, in raplace ment of the include bit.

you following? ish?

EDIT: more deatil on it in the php maule http://us3.php.net/include/

(the site tends to confuse me so i learn form other places

splintercell!
28-02-2005, 04:37 PM
What he said :D Its working really well by the way
Basically is you go on mentor's site www.thybag.co.uk then click on one of the navigation links you will see how it works :)

Want to hide these adverts? Register an account for free!