Setting a variable when clicking link
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Setting a variable when clicking link
I have a stupid question but here it is
When you click on a link, it sets a variable and then then page is reloaded. Depending on what variable it loads it will have different things show up on the site. For example
Link 1 is clicked and it loads the contents of link 1 inside the specified table. Anyone got a solution or tutorial? Thanks a bunch!
Phenom
When you click on a link, it sets a variable and then then page is reloaded. Depending on what variable it loads it will have different things show up on the site. For example
Link 1 is clicked and it loads the contents of link 1 inside the specified table. Anyone got a solution or tutorial? Thanks a bunch!
Phenom
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I've been looking around and trying stuff like
something along that line but what I am really looking for is to have 1 file global.php with all the variables setup with all the content and the index.php just puts on the correct information on the site depending on the variables. If you need furthur explanation jus ask :d
Code: Select all
<?php
$_SERVERї'PHP_SELF'] = "$page";
echo "images/$page";
?>-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
You could do something like this
Then, in page.php have this
Or page.php could look like this
Code: Select all
<a href="page.php?link=1">1 link</a>
<a href="page.php?link=2">2 link</a>Code: Select all
<?php
$link = $_REQUEST['link']
if ( isset($link == false ) {
die("You didn't follow a link here");
}
if ( $link == "1" ) {
echo "You clicked on link 1";
} elseif ( $link == "2" ) {
echo "You clicked on link 2";
}
?>Code: Select all
<?php
$link = $_REQUEST['link']
if ( isset($link == false ) {
die("You didn't follow a link here");
}
echo "You clicked on link ".$link;
?>Client Side
Isnt there a Client Side thingie with GTK-php ?
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I'm gettting a parse error with this
The reason I'm using php is because I'm going to have a lot of other things on my site that requires php so I would rather keep it 100% php based.
Code: Select all
if ( isset($link == false ) {The reason I'm using php is because I'm going to have a lot of other things on my site that requires php so I would rather keep it 100% php based.
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
try this
Code: Select all
if ( isset($link == false ) ) {- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
no luck, still getting parse erorr on line 7.. which is that line
*update*
nvm the parse error was for the line before it
which was
changed to
silly me ty a lot
*update*
nvm the parse error was for the line before it
which was
Code: Select all
$link = $_REQUESTї'link']Code: Select all
$link = $_REQUESTї'link'];
Last edited by John Cartwright on Wed Jan 14, 2004 2:44 pm, edited 1 time in total.
-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
Use this code as your page.php
Or
Code: Select all
<?php
if ( isset($_REQUEST['link']) == false ) {
die("You didn't follow a link here");
}
$link = $_REQUEST['link']
if ( $link == "1" ) {
echo "You clicked on link 1";
} elseif ( $link == "2" ) {
echo "You clicked on link 2";
}
?>Code: Select all
<?php
if ( isset($_REQUEST['link']) == false ) {
die("You didn't follow a link here");
}
$link = $_REQUEST['link']
echo "You clicked on link ".$link;
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I had problems with the code you gave me so I removed a little bit of it and it seemed to be working fine but here is what I am with right now.
What the problem is it loads the main page right away....and then when I click on the links it brings me to the correct page but with the main page under it. I tried changing the includes to include_once() but didn't have any luck. Any Ideas??? TY !!
Code: Select all
<?php
$link = $_REQUESTї'link'];
if ( $link == "2" ) {
include("portfolio.php");
}
if ( $link == "3" ) {
include("faq.php");
}
if ( $link == "4" ) {
include("pricing.php");
}
if ( $link == "5" ) {
include("aboutme.php");
}
if ( $link == "6" ) {
include("mycomputer.php");
}
if ( $link == "7" ) {
include("tutorials.php");
}
if ( $link == "8" ) {
include("contact.php");
}
else
{
include("main.php");
}
?>-
Straterra
- Forum Regular
- Posts: 527
- Joined: Mon Nov 24, 2003 8:46 am
- Location: Indianapolis, Indiana
- Contact:
This is because of your If statements, try this code
Code: Select all
<?php
$link = $_REQUEST['link'];
if ( $link == "2" ) {
include("portfolio.php");
} elseif ( $link == "3" ) {
include("faq.php");
} elseif ( $link == "4" ) {
include("pricing.php");
} elseif ( $link == "5" ) {
include("aboutme.php");
} elseif ( $link == "6" ) {
include("mycomputer.php");
} elseif ( $link == "7" ) {
include("tutorials.php");
} elseif ( $link == "8" ) {
include("contact.php");
} else {
include("main.php");
}
?>Also, you might make your life a little easier (and the user's, actually) by rewriting it like so:
Example link:
<a href="sections.php?link=portfolio">Portfolio</a>
Code: Select all
$link = $_REQUEST['link'];
if($link)
{
include($link . ".php");
} else
{
include("main.php");
}<a href="sections.php?link=portfolio">Portfolio</a>
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: