Pass information through link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Batric
Forum Newbie
Posts: 7
Joined: Mon Nov 03, 2008 2:55 am

Pass information through link

Post by Batric »

Hi to everyone

Here's my code:
first_page.html

Code: Select all

<html>
<head>
<title>First</title>
</head>
<body>
<a href="second_page.html">Link 1</a><br />
<a href="second_page.html">Link 2</a><br />
<a href="second_page.html">Link 3</a>
</body>
</html>
 
second_page.html

Code: Select all

<html>
<head>
<title>Second</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
  <label>
    <select name="link" id="link">
      <option value="Link 1">Link 1 was selected</option>
      <option value="Link 2">Link 2 was selected</option>
      <option value="Link 3">Link 3 was selected</option>
    </select>
  </label>
</form>
</body>
</html>
 
How to connect these two pages, so when I click on Link 2 on the first page, the second pages opens and the Link 2 was selected is choosed?

Thank you in any case :)

Batric
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: Pass information through link

Post by pavanpuligandla »

Code: Select all

[quote]first_page.html
Line number On/Off | Expand/Contract
 
   1. <html>
   2. <head>
   3. <title>First</title>
   4. </head>
   5. <body>
   6. <a href="second_page.html">Link 1</a><br />
   7. <a href="second_page.html">Link 2</a><br />
   8. <a href="second_page.html">Link 3</a>
   9. </body>
  10. </html>
  11.  [/quote]
simply change href's in the first page as

Code: Select all

<a href="second_page_link1.html">Link 1</a><br />
make link1 appear in the second page and the rest 2 invisible.

Code: Select all

<a href="second_page_link2.html">Link 2</a><br />
make link2 appear in the secondpage and the rest 2 invisible

is thisyou want to do?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Pass information through link

Post by aceconcepts »

I've amended your script. This should work for you:
Batric wrote:Hi to everyone

Here's my code:
first_page.html

Code: Select all

<html>
<head>
<title>First</title>
</head>
<body>
<a href="second_page.html?link=1">Link 1</a><br />
<a href="second_page.html?link=2">Link 2</a><br />
<a href="second_page.html?link=3">Link 3</a>
</body>
</html>
 
second_page.html

Code: Select all

<html>
<head>
<title>Second</title>
</head>
<body>
<?
//GET link VARIABLE FROM URL
if(isset($_REQUEST['link']) && !empty($_REQUEST['link']))
{
   $link=$_REQUEST['link'];
}
?>
<form id="form1" name="form1" method="post" action="">
  <label>
    <select name="link" id="link">
      <option value="Link 1" <? if($link==1){ echo'selected="selected"'; ?>>Link 1 was selected</option>
      <option value="Link 2" <? if($link==2){ echo'selected="selected"'; ?>>Link 2 was selected</option>
      <option value="Link 3" <? if($link==3){ echo'selected="selected"'; ?>>Link 3 was selected</option>
    </select>
  </label>
</form>
</body>
</html>
 
How to connect these two pages, so when I click on Link 2 on the first page, the second pages opens and the Link 2 was selected is choosed?

Thank you in any case :)

Batric
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Pass information through link

Post by requinix »

You have a couple unclosed if{...} blocks in there. And $link would be undefined if someone got to the second page without a &link=.

Code: Select all

<html>
<head>
<title>Second</title>
</head>
<body>
<?
//GET link VARIABLE FROM URL
if(isset($_REQUEST['link']) && !empty($_REQUEST['link']))
{
   $link=$_REQUEST['link'];
}
else
{
   $link=0;
}
?>
<form id="form1" name="form1" method="post" action="">
  <label>
    <select name="link" id="link">
      <option value="Link 1" <? if($link==1) echo 'selected="selected"'; ?>>Link 1 was selected</option>
      <option value="Link 2" <? if($link==2) echo 'selected="selected"'; ?>>Link 2 was selected</option>
      <option value="Link 3" <? if($link==3) echo 'selected="selected"'; ?>>Link 3 was selected</option>
    </select>
  </label>
</form>
</body>
</html>
Seriously, who indents using three spaces? Two yes, four yes, even eight, but three?
Batric
Forum Newbie
Posts: 7
Joined: Mon Nov 03, 2008 2:55 am

Re: Pass information through link

Post by Batric »

@aceconcepts
That's what I looked for
Thank you a lot! :D
Batric
Forum Newbie
Posts: 7
Joined: Mon Nov 03, 2008 2:55 am

Re: Pass information through link

Post by Batric »

tasairis wrote: Seriously, who indents using three spaces? Two yes, four yes, even eight, but three?
If you think of my post - I used Dreamweaver :)
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Pass information through link

Post by aceconcepts »

@tasairis
What's the deal with indents??? Who cares how many spaces there are.

Concentrate more on solving the issue at hand.

@Batric
I'm glad it worked for you :D
Batric
Forum Newbie
Posts: 7
Joined: Mon Nov 03, 2008 2:55 am

Re: Pass information through link

Post by Batric »

I have one more question:

How can I connect some random object and php? Here's the example:

Code: Select all

<html>
<body>
<img name="first" src="" width="32" height="32" alt="">
<img name="second" src="" width="32" height="32" alt="">
<img name="third" src="" width="32" height="32" alt="">
<img name="fourth" src="" width="32" height="32" alt="">
<img name="fifth" src="" width="32" height="32" alt="">
</body>
</html>
 
When I click on first image, the value of $test should be first etc

Any ideas?

Thanks again
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Pass information through link

Post by aceconcepts »

You could place the image within a hyperlink:

Code: Select all

<a href="?test=first"><img name="first" src="" width="32" height="32" alt=""></a>
and then do the same as before, with regard to $_REQUEST[''] etc...
Batric
Forum Newbie
Posts: 7
Joined: Mon Nov 03, 2008 2:55 am

Re: Pass information through link

Post by Batric »

That would be it, but the page should not reload.

Do you know how to do it with ajax?
Post Reply