I thought I had a pretty good idea of what I was doing trying to get rows of information from a MySQL database, but now that I'm just trying to get one little field from a database I'm stumped.
Here's a code sample:
$connection = connect_db(); // call a user-defined function for this, works fine
$username = "rocky";
// note the following query works fine from the MySQL command line
// (substituting the var of course)
// it normally returns an integer, the user_id
$query = "SELECT user_id FROM users WHERE user_name = '$username'";
$result = mysql_query($query, $connection); // no errors here
// so now how do I get that user_id from $result?
while ($row = msql_fetch_array($result))
$user_id = $row['user_id'];
The above all works fine up to the last command. I'm not sure an array is returned at all, since all I'm supposed to get back from the query is a single integer. I've tried noodling around without the "loop" and using subscripts, but so far nothing gets it out.
I'm sure it's simple. What do I need to do?