Joined
·
16 Posts
[SOLVED] mySQL if no results found **....}?
function getrank($userid) **
global $clanrank;
//Database configuration:
include("configuration.php");
//Connect to database:
mysql_connect("$server", "$username", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());
$result = mysql_query("SELECT * FROM ranklist WHERE user_id='$userid'");
// Turn the result row into a array
$array = mysql_fetch_array($result);
// Assign globalised variable to sellected data
$clanrank = $array['rank'];
}
This is my current code for retriving the users rank from a mySQL database. Some users don't have a entry on the table and are therefore "recruit" rank. Once thier rank raises i add a entry on the table for them.
Is there anyway to tell PHP
if (no entry on table) ** $rank = recruit }
else **
// Turn the result row into a array
$array = mysql_fetch_array($result);
// Assign globalised variable to sellected data
$clanrank = $array['rank'];
}
PS: Im NOT SURE where i should do the mysql_fetch_array(); function.
before the if - else statement or inside it.
function getrank($userid) **
global $clanrank;
//Database configuration:
include("configuration.php");
//Connect to database:
mysql_connect("$server", "$username", "$password") or die(mysql_error());
mysql_select_db("$database") or die(mysql_error());
$result = mysql_query("SELECT * FROM ranklist WHERE user_id='$userid'");
// Turn the result row into a array
$array = mysql_fetch_array($result);
// Assign globalised variable to sellected data
$clanrank = $array['rank'];
}
This is my current code for retriving the users rank from a mySQL database. Some users don't have a entry on the table and are therefore "recruit" rank. Once thier rank raises i add a entry on the table for them.
Is there anyway to tell PHP
if (no entry on table) ** $rank = recruit }
else **
// Turn the result row into a array
$array = mysql_fetch_array($result);
// Assign globalised variable to sellected data
$clanrank = $array['rank'];
}
PS: Im NOT SURE where i should do the mysql_fetch_array(); function.
before the if - else statement or inside it.