Send variable by pressing hyperlink?

This is a discussion on "Send variable by pressing hyperlink?" within the PHP Forum section. This forum, and the thread "Send variable by pressing hyperlink? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 6th, 2008, 00:32
Junior Member
Join Date: Jan 2008
Location: Reykjavik
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Send variable by pressing hyperlink?

Hi, Iīm completely stuck on this one.
I have a search that displays the search results like so:

1. Name
__Some short description for that name...

2. Name 2
__Some short description for that name...

3. etc....

or in PHP like so...
PHP: Select all

while ($rowmysql_fetch_array($result)) {
  
$name $row["Name"];
  
$description $row["Description"];

  echo 
"<p>$count.)&nbsp;<a href=\"http://xxxxxxxxxx/show_name.php (here is my problem)\"> $name </a> \n</p>";
  echo 
"<p>&nbsp;&nbsp;&nbsp;$description \n</p>";
  
$count++ ; 
Now for my problem. The "show_name.php" displays informations from several fields in my database for a given 'ID' row in the database.
Where 'ID' is a integer, auto-increment and primary.

What I would like to do here is that when that LINK is clicked a pop-up window should open "show_name.php" and set the variable $id to the corresponding number where "NAME" is in my database.
So in show_name.php I can have this code:
PHP: Select all

$data mysql_query("SELECT * FROM TABLE where id ='$id'")
or die(
mysql_error()); 
Now the show_name.php knows what "name" it should look up in the database and can display all the correspondingly information.

How is this possible?
I hope this is understandable!

To round it up, "show_name.php" should get information from the search result page what NAME to display information about. Note that there are numerous results as shown in the text above.
This might be an easy one, i've just been looking at this for to long!

Last edited by skuliaxe; Feb 6th, 2008 at 17:16. Reason: Solved by alexgeek
Reply With Quote

  #2 (permalink)  
Old Feb 6th, 2008, 01:18
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Send variable by pressing hyperlink?

Can I see your query for the first page please?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Feb 6th, 2008, 10:52
Junior Member
Join Date: Jan 2008
Location: Reykjavik
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Send variable by pressing hyperlink?

Quote:
Originally Posted by alexgeek View Post
Can I see your query for the first page please?
Here is my query from the Search Results page:
PHP: Select all

$query "select * from TABLE where COLUMN like \"%$trimmed%\" order by COLUMN";

 
$numresults=mysql_query($query);
 
$numrows=mysql_num_rows($numresults);

...
...
// Then to display the search results
  
while ($rowmysql_fetch_array($result)) {
  
$name $row["Name"];
  
$Description $row["Description"];
  
$id $row["id"];

  echo 
"<p>$count.)&nbsp;<a href=\"http://xxxx.com/show_name.php"$name </an</p>";
  echo "
<p>&nbsp;&nbsp;&nbsp;$Description n</p>";
  $count++ ; 
There I need to pass that $id variable to the next PHP page (show_name.php) via a HYPERLINK. Thatīs the only thing showing on the Search results page, a hyperlink to show_name.php

This all would be much easier if every entry in the database would have itīs unique page, but thatīs a big waste of space and I plan on having huge numbers of entries.

I have also used something like this (to open the "show_name.php" as a pop-up with no menu and fixed size).

PHP: Select all

  while ($rowmysql_fetch_array($result)) {
  
$name $row["Name"];
  
$Description $row["Description"];
  
$id $row["id"];

  echo 
"<p>$count.)&nbsp;<a href=\"\" onClick='open_win()'> $name </a> \n</p>";
  echo 
"<p>&nbsp;&nbsp;&nbsp;$Description \n</p>";
  
$count++ ; 
And in top of the page is this java function:
HTML: Select all
<script type="text/javascript">
function open_win() 
{
window.open('http://xxxxxxx.com/show_name.php?q=$id','height=900,width=850,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
}
There I was hoping to be able to SET the search string as $id. But it seems as thatīs not possible. Every time in the Search results that LINK doesn't have the $id but just the Search string that the user entered.
Reply With Quote
  #4 (permalink)  
Old Feb 6th, 2008, 10:57
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Send variable by pressing hyperlink?

Try this:
PHP: Select all

echo "<p>$count.)&nbsp;<a href=\"http://xxxxxxxxxx/show_name.php?id=".$row["id"]."(here is my problem)\"> $name </a> \n</p>"

And then in show_name.php:
PHP: Select all

$id $_GET['id'];
$data mysql_query("SELECT * FROM TABLE where id ='$id'"
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #5 (permalink)  
Old Feb 6th, 2008, 13:25
Junior Member
Join Date: Jan 2008
Location: Reykjavik
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Send variable by pressing hyperlink?

That did the trick, thank you so much for that
PHP: Select all

echo "<p>$count.)&nbsp;<a href=\"http://xxxxxx.com/show_name.php?id=".$row["id"]."\"> $name </a> \n</p>"
Only thing left is to have the Link open in a pop-up window with certain settings.
I would like to have the following setting on a pop-up window:
HTML: Select all
function open_win() 
 {
 window.open('http://xxxxxxx.com/show_name.php?id=".$row["id"]."','Page title','height=900,width=850,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
 }
I know that now there is a PHP code in a Jave script. (".$row["id"].) That is just to illustrate what I would like.


In stead of the current link (in first code above) opening the page in the same window, I would like to open it in a pop-up window. Could a java script help here?
PHP: Select all

echo "<p>$count.)&nbsp;<a href=\"\" onClick='open_win()'> $name </a> \n</p>"
To call the script from the second code in this post?
Reply With Quote
  #6 (permalink)  
Old Feb 6th, 2008, 13:28
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Send variable by pressing hyperlink?

Replace the echo with:
PHP: Select all

?>
function open_win() 
 {
 window.open('http://xxxxxxx.com/show_name.php?id=<?php echo $row["id"]; ?>','Page title','height=900,width=850,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
}
<?php
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)

Last edited by alexgeek; Feb 6th, 2008 at 13:31.
Reply With Quote
  #7 (permalink)  
Old Feb 6th, 2008, 16:35
Junior Member
Join Date: Jan 2008
Location: Reykjavik
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Send variable by pressing hyperlink?

OK, i did something similar to what you suggested:
PHP: Select all

<?php
while ($rowmysql_fetch_array($result))
  {
      
$name $row["name"];
      
$description $row["Description"];
      
$id $row["id"];

  
      echo 
"<p>$count.)&nbsp;<a href=\"\" onClick='open_win()'> $name </a> \n</p>";
        
?>  <script type="text/javascript">
            function open_win() 
            {
            window.open('http://xxxxxx.com/show_name.php?id=<?php echo $id?>','Page title','height=900,width=850,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
            }
            </script><br />
        <?php
      
echo "This is id# $id \n"//For testing purposes
      
echo "<p>&nbsp;&nbsp;&nbsp;$Description \n</p>";
      
$count++ ;
  }
This helped to fix the LINK. But only when there is ONE search result. When there are multiple search results, the value in $id displays correctly, but the LINK always acts as the value "1" in every link.

Here is what I see from the code above and my search results of the letter "a":

1. Name 1
__This is id# 3
__Description...........

2. Name 2
__This is id# 5
__Description...........

3. Name 3
__This is id# 1
__Description.............

4. etc.

But every link acts like the $id is "1". Even though the id is printed correctly below the name.

When I do a more accurate search like "Name X", and only get ONE result everything works great. No matter if itīs Name 1, 2, 3..... then the link always acts correctly.

Any ideas
Reply With Quote
  #8 (permalink)  
Old Feb 6th, 2008, 16:45
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Send variable by pressing hyperlink?

That would be because you are creating the function in javascript many times, resulting in it being overridden.
try:
PHP: Select all

      echo "<p>$count.)&nbsp;<a href=\"\" onClick='open_win(".$row['id'].")'> $name </a> \n</p>";
        
?>  <script type="text/javascript">
            function open_win(id) 
            {
            window.open('http://xxxxxx.com/show_name.php?id='+id,'Page title','height=900,width=850,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
            }
            </script><br /> 
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Feb 6th, 2008, 17:08
Junior Member
Join Date: Jan 2008
Location: Reykjavik
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Send variable by pressing hyperlink?

Thanks a million, you can mark this as SOLVED
Notice now that it was always the last $id that was being sent forward due to the overwriting, right?

P.s.: Iīm not good in the programing department (beginner). But every time I get help then I most of the time know why something didn't work before. I hope these problems I was having aren't extremely stupid.

I would also like thank you for the extremely fast replies.

Last edited by skuliaxe; Feb 6th, 2008 at 17:10.
Reply With Quote
  #10 (permalink)  
Old Feb 6th, 2008, 18:02
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Send variable by pressing hyperlink?

Btw you can remove this:
HTML: Select all
 <script type="text/javascript">
            function open_win(id) 
            {
            window.open('http://xxxxxx.com/show_name.php?id='+id,'Page title','height=900,width=850,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
            }
            </script>
To the <head> of your page, otherwise it's in the loop and gets repeated.


Thread Sovlved has been disabled for now
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)

Last edited by c010depunkk; Feb 7th, 2008 at 06:07.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to multiply without pressing button codeexplorer JavaScript Forum 2 Oct 1st, 2007 11:25
Hyperlink buttons scoopslack Flash & Multimedia Forum 3 Mar 8th, 2007 13:02
A hyperlink that passes a variable to a page oz_egirl Classic ASP 1 Jan 18th, 2006 16:23
Two form actions on pressing submit button? AndyP Web Page Design 7 Jul 25th, 2005 16:25


All times are GMT. The time now is 11:55.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43