Re: Random pick
| From: | Peter Beckman | Date: | Mon, 25 Jan 2010 20:24:23 +0000 |
| Subject: | Re: Random pick | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46801@lists.php.net to get a copy of this message | ||
On Mon, 25 Jan 2010, Karl DeSaulniers wrote:
Thank you for this as well. Question? What part is "in_array" playing? Is it comparing $req_user_level to array()? Because the text "Guest", etc.. is not in $req_user_level on the database. In other words, is it checking the value of $req_user_level to see if "Guest" is in it?Sorry, I missed the question mark. in_array isn't appropriate here. The previous poster has it right, assuming $req_user_level is an integer of 0..9. $levels = array("Guest", "Regular User", 'Intl. User', ...)
// the array is 0 , 1 , 2 , ...)Going a little further:
if (!empty($levels[$req_user_level])) { // is both set and doesn't evaluate to false
echo "The user is a {$levels[$req_user_level]}.\n";
} else {
// The $req_user_level was not a valid level.
echo "The returned req_user_level was not valid.\n";
}
Which would output, if $req_user_level was 1 (one):
The user is a Regular User.Then you know you have a valid user level. Careful though -- sometimes 0 will be returned on a failure, depending on your SQL. Beckman ---------------------------------------------------------------------------
Peter Beckman Internet Guy beckman@angryox.com http://www.angryox.com/---------------------------------------------------------------------------