Page 1 of 2

pass a variable from one page to another

Posted: Mon Jan 22, 2007 12:42 pm
by tarja311
Hi all.

I'm trying to pass a variable from one page to another but having a difficult time doing so. I have two pages. Page 1 pulls data in from a database and displays it. Page 2 is simply the "more detailed info" type page that gets displayed when the mouse is hovered over the results ( in a tooltip kind of fashion ). Now, the mouse-hovering and detailed info works great. The only problem i am having is not being able to pass the $id from Page1 to Page2 where it can show this info automatically cause right now, in Page2, i have to type in the $id manually ( eg : $id = 32 ) to get a result.

I am not sure what to do now.

Page 1 - pulling data in from my database

Code: Select all

while($r = mysql_fetch_array($sql))
{
	$id		=	$r["F_ID"];
	$file		=	$r["F_FILENAME"];

	echo "<TD><A HREF = '?w=result&cmd=filename&id=$id' onmouseover = ajax_showTooltip('tooltip.php',this);return false onmouseout=ajax_hideTooltip()>". $file ."</A></TD>";	
}


If more info is needed i'll be more than happy to give it.

Thanks.

-- tarja

Posted: Mon Jan 22, 2007 12:48 pm
by Kieran Huggins
use a session?

Posted: Mon Jan 22, 2007 12:51 pm
by tarja311
If you mean session_start(); , that is already in place at the top of both pages.

Posted: Mon Jan 22, 2007 12:51 pm
by volka
Does the right id= show up in the url when you press the link?
tarja311 wrote:in Page2, i have to type in the $id manually ( eg : $id = 32 ) to get a result.
What's your "not-manually" code? Probably contains something like $id=$_GET['id']. Check the parameters via var_export($_GET);

Posted: Mon Jan 22, 2007 12:55 pm
by Kieran Huggins
anything you store inside the $_SESSION array will be preserved for the whole session

Posted: Mon Jan 22, 2007 12:58 pm
by tarja311
Does the right id= show up in the url when you press the link?
Yes. i receive a : ?w=result&cmd=filename&id=$id=31
What's your "not-manually" code? Probably contains something like $id=$_GET['id']. Check the parameters via var_export($_GET);
In Page 2 i am just calling to the database and declaring the variable myself like so :

Code: Select all

$id = 31;
$result  = mysql_query("SELECT * FROM `". $my_result_table. "` WHERE `F_ID` = '$id'");
I do not have any $_GET's because i thought i needed a form to use them. :-S

Posted: Mon Jan 22, 2007 1:02 pm
by jammr
Just store the ID variable on the first page in a session and in the second page use the session variable.

Posted: Mon Jan 22, 2007 1:20 pm
by tarja311
Ok. I put it in a session as follows ( stop me if i'm using this incorrectly ) :

Page 1

Code: Select all

while($r = mysql_fetch_array($sql))
{
        $id          =    $r["F_ID"];
        $file      =  $r["F_FILENAME"];

        echo "<TD><A HREF = '?w=result&cmd=filename&id=$id' onmouseover = ajax_showTooltip('tooltip.php',this);return false onmouseout=ajax_hideTooltip()>". $file ."</A></TD>";       

$_SESSION['id'] = $id_file;

}
Page 2

Code: Select all

$id_file = $_SESSION["id"];

$result  = mysql_query("SELECT * FROM `". $db_xoc_table. "` WHERE `F_FILE_ID` = '$id_file'");
So far it is only picking up the first result. It does not seem to be dynamic at the moment. Any ideas?

Posted: Mon Jan 22, 2007 1:26 pm
by volka
Do you want
a) to pass an id with each url so details are displayed according to the link that was activated/clicked?
b) to store one id in the session data so that no matter what link was clicked the details of this one record is displayed?
c) both?

Posted: Mon Jan 22, 2007 1:26 pm
by jammr

Code: Select all

$id_file = $_SESSION["id"];

$result  = mysql_query("SELECT * FROM `". $db_xoc_table. "` WHERE `F_FILE_ID` = '$id_file'");

Check the session variable in this bit again... should be $_SESSION['id'] :D

Posted: Mon Jan 22, 2007 3:30 pm
by tarja311
I appreciate all the help so far.

Using $_SESSION still only displays details of the first record inside the tooltip, even with it inside the while-loop. I guess it does not refresh itself ( static ) when i hover my mouse over a different result.
Do you want
a) to pass an id with each url so details are displayed according to the link that was activated/clicked?
I guess that is what i am trying to do. However, the link does not get clicked, it gets hovered over, displaying the detailed tooltip. As i mentioned, so far i am able to retreive the detailed info, but only if i specify the id myself. :?

Posted: Mon Jan 22, 2007 3:37 pm
by Mohamed
tarja311 wrote:
Do you want
a) to pass an id with each url so details are displayed according to the link that was activated/clicked?
I guess that is what i am trying to do. However, the link does not get clicked, it gets hovered over, displaying the detailed tooltip. As i mentioned, so far i am able to retreive the detailed info, but only if i specify the id myself. :?
then pass variable like this way http://example.com/tooltip.php?id=whatever_id.

and use $_GET['id'] to retrieve the value of the variable.

like this way

Code: Select all

if(isset($_GET['id']){
$id = $_GET['id'];
}

Posted: Mon Jan 22, 2007 4:44 pm
by tarja311
then pass variable like this way http://example.com/tooltip.php?id=whatever_id.

and use $_GET['id'] to retrieve the value of the variable.
Stupid question, but how do i make my url like that if i am not clicking on the results, but hovering over them with my mouse? Or maybe your suggestion is unclear to me.

Anyways i did try as u suggested but to no avail. :?

Page 1's url is like so : http://site/?w=result while Page 2's url is not attached in this way. it is accessed as just 'tooltip.php'.

Posted: Mon Jan 22, 2007 5:05 pm
by Mohamed
your code

Code: Select all

while($r = mysql_fetch_array($sql))
{
        $id          =    $r["F_ID"];
        $file      =  $r["F_FILENAME"];

        echo "<TD><A HREF = '?w=result&cmd=filename&id=$id' onmouseover = ajax_showTooltip('tooltip.php',this);return false onmouseout=ajax_hideTooltip()>". $file ."</A></TD>";       
}
modified one

Code: Select all

while($r = mysql_fetch_array($sql))
{
        $id          =    $r["F_ID"];
        $file      =  $r["F_FILENAME"];

        echo "<TD><A HREF = '?w=result&cmd=filename&id=$id' onmouseover = ajax_showTooltip('tooltip.php?id=$id',this);return false onmouseout=ajax_hideTooltip()>". $file ."</A></TD>";       
}
tooltip.php?id=$id

so in tooltip.php

use this code to get value of id

Code: Select all

if(isset($_GET['id'])){
    $id = $_GET['id'];
}
is that clear?

Posted: Mon Jan 22, 2007 5:09 pm
by Mohamed
tarja311 wrote: Stupid question, but how do i make my url like that if i am not clicking on the results, but hovering over them with my mouse? Or maybe your suggestion is unclear to me.

Anyways i did try as u suggested but to no avail. :?

Page 1's url is like so : http://site/?w=result while Page 2's url is not attached in this way. it is accessed as just 'tooltip.php'.
if you can load tooltip.php, why not tooltip.php?id=20