Web Hosting Talk







View Full Version : Simple ish PHP question


Georgecooldude
03-25-2005, 06:32 PM
I am trying to design a webpage. It looks like this:

I want a user to click on link 1 and it display "This is content 1" and then I want a user to be able to click on link 2 and it display "This is content 2"

How can I program that in php? I know I need to give them variable names but I'm not sure I would get the content bit to display a certain link1 or link2's infomation when either one of those links is clicked.

I think its probably fairly easy but I've never done it before. Maybe someone could show me an example. Thanks. :-)


edit
ok, my formatting messed up, so i tryed to attach but cant find the option. :S so i'll include a link to what i mean.

http://www.d3hq.com/images/example1.jpg

mouldy_punk
03-25-2005, 06:44 PM
You could do that with standard HTML...maybe I'm misunderstanding you...

Do you mean like, you click on link one and it'll go to say, file.php?page=1 and if you click on link 2 it'll go to file.php?page=2? If that's what you mean, you could just do a switch script

Georgecooldude
03-25-2005, 06:48 PM
I could use html but I'm trying to build in a feature so that I can eventually get some sort of admin panel setup.

For my feature to work would I have to use file.php=page2? or could I have to load within the content page? I guess im trying to use a feature similar to frames but im not wanting to do that.



Could you show me the ways it could be done? I've seen on some sites you can click any link and just a tiny bit of content in the main section of the site changes. the URL stays the same. Maybe what im asking is impossible, im not sure. But i'm interested in all the possible ways.

jonathanbull
03-25-2005, 09:00 PM
Not sure if this is what you're looking for, but this simple script would do the job.... Save the file with the below coding as example.php



<p><a href="test.php?t=1">text1</a></p>

<p><a href="test.php?t=2">text2</a></p>

<p><a href="test.php?t=3">text3</a></p>

<?

// Get the number from the address bar

$number = $_GET['t'];


// Display text depending on what number was in the address bar

if ($number == "1") { echo "text1 was clicked"; }
if ($number == "2") { echo "text2 was clicked"; }
if ($number == "3") { echo "text3 was clicked"; }


?>



Hope it helps!

- Jon.

jonathanbull
03-26-2005, 01:20 PM
Originally posted by jonathanbull Not sure if this is what you're looking for, but this simple script would do the job.... Save the file with the below coding as example.php
Sorry, that's supposed to be test.php!

Georgecooldude
03-26-2005, 05:42 PM
Hi Jon,

Thanks I'll have a play about with this now. :-)

Georgecooldude
03-26-2005, 05:59 PM
Thanks Jon,

I tryed your above code. The problem i have is that the page flickers when a link is clicked so I think it effeectibly reloads..

Is there any way to have just a table cell update and avoid the flicker?

krumms
03-26-2005, 06:26 PM
Thanks Jon,

I tryed your above code. The problem i have is that the page flickers when a link is clicked so I think it effeectibly reloads..

Is there any way to have just a table cell update and avoid the flicker?


sure, if you don't mind your entire site being loaded all at once, and your poor user waiting half an hour for it all to finish downloading :P

it IS possible to do something like what you're asking using what people are calling (to my disgust) "Ajax" - which is essentially JavaScript & the XMLHttpRequest object - but it's far more effort than it's worth, and your code will more than likely be completely unmaintainable.

crazyb8ss
03-26-2005, 10:53 PM
Hope this helps

<?
//Retrieve Varibles
$pg=$_REQUEST['page'];

//Find Page Title
if($pg == 1){
$page="Text1";
}
if($pg == 2){
$page="Text2";
}
if($pg == 3){
$page="Text3";
}


//HTML

print "<title>" . $page . "</titlle>";
print "<p> You are currently on page" . "$page";
print "<a href=help.php?pg=1>Text1</a><br>";
print "<a href=help.php?pg=2>Text2</a><br>";
print "<a href=help.php?pg=3>Text3</a><br>";




It could be done even easier with arrays, but I dont want to miscode that and confuse ;)

Georgecooldude
03-27-2005, 12:09 PM
Thanks guys.

Could you also show me the javascript way to make just that content reload and not the entire page.

When a link is clicked it flashes white and then loads and then shows the page. I just want to get rid of this now and then im sorted. :D