Tutorial Return Only One Variable from MySQL Query

by in , 0

Function

function mysql_get_var($query,$y=0){
       $res = mysql_query($query);
       $row = mysql_fetch_array($res);
       mysql_free_result($res);
       $rec = $row[$y];
       return $rec;
}

Usage

$name = mysql_get_var("SELECT name from people where email = 'roger@freekrai.net'");

Will return the name field, so what gets returned will be "Roger" (if that was my name in the database).

Reference URL

Leave a Reply