Jump to content

[SOLVED] If SQL Value Exists


pugboy

Recommended Posts

I'm sure there is something better but this is close to what I always use

<?php
$query = "SELECT username FROM users WHERE username = '{USERNAME}'";
$sql = mysql_query($query);
if(mysql_num_rows($sql)) {
    /* User Exists Code */
} else {
    /* User NOT Exists Code */
}
?>

<?php
$query = "Select `attribute` from Table where `attribute`  = 'value' ";
$result = mysql_query($query);

if(mysql_num_rows($result)){
    value exists
}else{

it doesn't

}
?>

 

 

beat me to it....and with near exact code too.

 

There is no boolean query that I'm aware of.  Besides, if you think about it, just a yes or a no wouldn't really save anything in terms of speed or efficiency.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.