Hello, I was wondering how I would call a variable i have declared in another php page.
ie. i have the php page Bob.php and want to call the variable $name from show.php.
any help is appreciated.
How to call a variable from a different php page?
Moderator: General Moderators
the only problem is, if my prior page had printed any data from the variable i'm calling from before on the previous page, it prints that same information at the top of the page. any ideas?
in other words, let's say i have the following names:
Bob
James
Sally
The way this code is working, it defines the variable $fname as bob, then james, and then sally. Instead of creating an array that can be called later, it defines $fname as Sally ONLY because it's the last name to be used to define #fname.
So, everytime i select one of the names to bring up info on the next page with, it will ONLY give me the information to Sally, and non of the others. Also, it's posting all the names at the top, instead of only the information i was wanting to see from the specific user Sally...
here is the code i'm using :
list.php
detail.php
However, there is a problem with this code. When you click one of the names, it WILL display the information you are wanting, however, the names stay at the top of the page ( meaning, not only does the name you want to view stay at the top, but ALL the first names in your database ). Also, should you try to select another name, the values do not change from the first name's values.
in other words, it doesn't clear the array. what am i doing wrong?
***********edit 3 ***************
i think the problem is that the variable $fname is being reassigned by each new name, and the very last name is the final value of it, making every link's details that is generated equal to only the last record value of fname...
help me 
in other words, let's say i have the following names:
Bob
James
Sally
The way this code is working, it defines the variable $fname as bob, then james, and then sally. Instead of creating an array that can be called later, it defines $fname as Sally ONLY because it's the last name to be used to define #fname.
So, everytime i select one of the names to bring up info on the next page with, it will ONLY give me the information to Sally, and non of the others. Also, it's posting all the names at the top, instead of only the information i was wanting to see from the specific user Sally...
here is the code i'm using :
list.php
Code: Select all
<html>
<head><title>Pick IP</title></head>
<body>
<?php
@ mysql_pconnect("localhost","username","password");
$db = mysql_select_db("people");
//* Get all records
$sql = "SELECT * FROM info";
$sql_result = mysql_query($sql);
while ($row = mysql_fetch_array($sql_result))
{
$fname = $rowї"fname"];
echo "<a href="detail.php?name=$name&fname=$fname">$fname</a>";
echo "<br />";
}
mysql_free_result($sql_result);
?>
</body>
</html>detail.php
Code: Select all
<html>
<head><title>Bob</title></head>
<body>
<?php
include 'list.php';
$sql = "SELECT * FROM info where fname = '$fname'";
$sql_result = mysql_query($sql);
while ($row = mysql_fetch_array($sql_result))
{
$detail = $rowї"address"];
$detail1 = $rowї"phone"];
echo "<br /> Detail : $detail <br /> Other Detail : $detail1 <br />";
}
mysql_free_result($sql_result);
?>
</body>
</html>However, there is a problem with this code. When you click one of the names, it WILL display the information you are wanting, however, the names stay at the top of the page ( meaning, not only does the name you want to view stay at the top, but ALL the first names in your database ). Also, should you try to select another name, the values do not change from the first name's values.
in other words, it doesn't clear the array. what am i doing wrong?
***********edit 3 ***************
i think the problem is that the variable $fname is being reassigned by each new name, and the very last name is the final value of it, making every link's details that is generated equal to only the last record value of fname...
Last edited by hibbard on Sun Nov 02, 2003 10:26 pm, edited 1 time in total.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
This is very similar to another thread, so I'm locking this one and sending all you helpful people to the other.
viewtopic.php?t=14226
Mac
viewtopic.php?t=14226
Mac