Return Only One Variable from MySQL Query

unnamed

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).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s