You not only can, but must. Unfortunately, too many young developers are used to picking too much data. After running the query, you do not need to do a while loop, since you only have one record. Instead, use only the following:
$sql = sprintf( "SELECT userid FROM users WHERE username = '%s'", $username ); $result = mysql_query( $sql ) or die( mysql_error() ); $data = mysql_result( $result, 0 ); if ( $data ) echo $data; // first userid returned
The second parameter to mysql_result() is the index of the row you want to get. 0 is the first.
Sampson
source share