So - basically this is what you want to do.
Get the name, email address and id for a member.
Get the name, email address and id for members who were referred by the above member.
This is what your code is doing:
$query = "SELECT CONCAT(firstname, ' , ' , lastname) AS name, email, id FROM maintable where referrer = '$memid' ORDER by (id) ASC"; // Getting a list of members
$result = @mysql_query ($query);//Run the query.
if ($result)
{
while ($row = mysql_fetch_array($result)){ // loop through the results
$row[0]</td><td><a href=\"mailto: // print name
$row[1]\">$row[1]</a></td><td> // print email
$row[2]</td></tr>\n"; // print id
}
So each time the while loop is run - you are resetting $row to be the next member in the list of results. $row[2] is not a list - its is a single variable - containing the id of the current member.
So if you want to get the list of members referred by the current member, you do it inside the while loop:
while ($row = mysql_fetch_array($result)){ // loop through the results
echo $row[0];
echo "<a href=\"mailto:$row[1]\">$row[1]</a>";
echo $row[2];
$curr_id = $row[2]; // put current id into a variable
$query = "SELECT CONCAT(firstname, ' , ' , lastname) AS name, email, id FROM maintable where referrer = '$curr_id' ORDER by (id) ASC";
// Do similar query processing and results presentation
}
Make sense?