This is all in one table from one database. Each row (with a unique id field) is represents data for a different person.
And there's one field in this table named "big" that represents the id field from another row (another person) in this same table. This isn't the exact situation but it's like a family tree and this field helps to display the first person's relative.
My basic query is like this and it works fine:
$id=$_GET['id'];
// query the DB
$sql = "SELECT * FROM table WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
echo "this 1st person\'s first name is ".$myrow["firstname"];
echo "this 1st person\'s relative is database entry number ".$myrow["big"];
That code above works fine. 🙂
But I don't want to just display their relative's number. I want to display their relative's name, which is found in a different row in the same table. So what I want to do is display the name (and other data) from the 2nd person. I can easily display $myrow["big"], which is a number, but how do I get data from the 2nd person, like the 2nd person's name?
😕
What I tried was to make a 2nd query with slightly altered names:
$id=$_GET['id'];
// query the DB
$sql = "SELECT * FROM brotherhood WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
echo "this person\'s first name is ".$myrow["firstname"];
$sql_big = "SELECT firstname FROM brotherhood WHERE id=25";
$result_big = mysql_query($sql_big);
$myrow_big = mysql_fetch_array($result_big);
echo "the first name of this person\'s relative is".$myrow_big["firstname"];
This code does indeed work and displays the first name of the 2nd person. But you'll notice that it only works because I manually stuck the number 25 (chosen at random) in the code. That number 25 should come from the 1st person's $big field. But everything I tried to replace "25" with the data entered in the $big field from the 1st person (the initial query) has failed.
Instead of "id=25" in the code above, I've tried...
id=$myrow["big"]
id=($myrow["big"])
id=$big
id=big
and several other attempts.
So what should I replace 25 to make id = the $big field from the first query result?
🙁