From: "Nathan Mealey" <[EMAIL PROTECTED]>

I cannot seem to access elements inside of the array $things in the code below. All of the errors say "Undefined offset: 7 in /Library/WebServer/Documents/lis/check.php on line 26" I don't see why...

The code is:

$q = "select * from users where email='".$email."' and password='".$pass."'";
$results = mysql_query($q);
if ($results) {
while ($list=mysql_fetch_assoc($results)) {
$things[]=$list;
}
}
//$things[7] is a MySQL timestamp column named "last_login"
$date = strtotime($things[7]);

You're creating a two dimensional array. $things[0][7] is the first row, eight column, which is what you're after if this only returns one row.


if you want to use $things[7], then within your while loop, use $things = $list;, for example. Although, if you're only getting one row, there's no need for a while loop and you can just say $things = mysql_fetch_assoc($results);

Oh, one more thing. fetch_assoc() returns an array with the keys named after the columns, not as numbers. So $things[0]['last_login'] or $things['last_login'] is what you're after. Or use mysql_fetch_row(), which will return keys as number... or use mysql_fetch_array(), which will do both.

have fun. Don't break anything.

---John Holmes...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to