Looking at the array you have posted;
Code: Select all
Array ( [0] => Array ( [0] => 2 [id] => 2 [1] => thommo [username] => thommo [2] => abc [password] => abc ) )
I am not sure what the layout is of your database table is, but to me this looks like the result of mysql_fetch_array($result, MYSQL_BOTH), and my guess is that you have the following fields; id, username, and password. The first part of the array "Array ( [0] => Array (..." is the result of the returned row. Since you are looking to return only one row in the result, you may want to look into using something like this:
Code: Select all
$result = mysql_query("SELECT * FROM user_data WHERE id = $id LIMIT 1");
if ($results) {
//Personally I prefer mysql_fetch_assoc which just returns the associative array portion of the result set like this
//list($members) = mysql_fetch_assoc($result);
//but there may be an advantage to using the result the way it is below
list($members) = mysql_fetch_array($result, MYSQL_BOTH);
}
print_r($members);
Doing it this way will result in:
Code: Select all
Array ( [0] => 2 [id] => 2 [1] => thommo [username] => thommo [2] => abc [password] => abc ) )
allowing you to use either $members[0] or $members['id'] to get the ID, $members[1] or $members['username'] to get the username, etc...
The key to this is the PHP list function. If you do not use the list function and just use this:
Code: Select all
$data = mysql_fetch_array($result, MYSQL_BOTH);
You would then need to reference $members[0][0] or $members[0]['id'] to get the ID and $members[0][1] or $members[0]['username'] to get the username, etc... Where $members[0] is the first and only row result.
using mysql_fetch_assoc with the list function would result in the following array:
Code: Select all
Array ( [id] => 2 [username] => thommo [password] => abc ) )
This would allow you to use $members['id'], $members['username'] or $members['password'] to reference any of the 3 fields.
Hope this explanation was helpful.