Page 1 of 1

Passing variables

Posted: Tue Dec 22, 2009 5:02 am
by dwsddas
Hi,

I have many php variables on my web page as links to another page, they display data from MySQL. I want one of this variable to be displayed on another page when I click on it. Please help how to do it.

Code: Select all

<?php
                            error_reporting(E_ALL ^ E_NOTICE);
                            mysql_connect("localhost","root") or die(mysql_error());
                            mysql_select_db("tttt") or die(mysql_error());
 
                            $query=mysql_query("SELECT * FROM textt");
                            while($row = mysql_fetch_array($query))
                            {
                                $textname = $row['textname'];
                                $textbody = $row['textbody'];
                                
                                echo "<a href=\"tet.php\"> $textname </a>";
                            }
                                
    
                        ?>

Re: Passing variables

Posted: Tue Dec 22, 2009 5:42 am
by MichaelR
Could you be a bit more clear about what you mean? My first impression is that something like this is what you need:

Code: Select all

 echo '<a href="tet.php?textname=' . $textname . '">' . $textname . '</a>';
So that the variable is available on the target page by accessing the $_GET super-global:

Code: Select all

 $textname = $_GET['textname'];

Re: Passing variables

Posted: Tue Dec 22, 2009 6:55 am
by dwsddas
I want $textname to be displayed on target page. I entered your code and it displays blank page.

Re: Passing variables

Posted: Tue Dec 22, 2009 8:11 am
by MichaelR
That's because my code simply defined the $textname variable. You'll need to ouput it using echo, for example, on the target page.

Re: Passing variables

Posted: Wed Dec 23, 2009 4:56 am
by dwsddas
Thanks. It works.