Passing variables

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
dwsddas
Forum Newbie
Posts: 8
Joined: Tue Dec 22, 2009 4:44 am

Passing variables

Post 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>";
                            }
                                
    
                        ?>
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: Passing variables

Post 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'];
dwsddas
Forum Newbie
Posts: 8
Joined: Tue Dec 22, 2009 4:44 am

Re: Passing variables

Post by dwsddas »

I want $textname to be displayed on target page. I entered your code and it displays blank page.
MichaelR
Forum Contributor
Posts: 148
Joined: Sat Jan 03, 2009 3:27 pm

Re: Passing variables

Post 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.
dwsddas
Forum Newbie
Posts: 8
Joined: Tue Dec 22, 2009 4:44 am

Re: Passing variables

Post by dwsddas »

Thanks. It works.
Post Reply