Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Condition based on highest level adopt owned? (http://www.mysidiaadoptables.com/forum/showthread.php?t=4709)

Kyttias 11-10-2014 01:01 PM

Condition based on highest level adopt owned? *solved*
 
How can I check if a user owns at least one adoptable above a certain level?

I'd like to bar entry to certain pages until the user has an adoptable "strong enough" to protect them there. I don't need a guide on how to make a custom page, just... the database statement.

edit: Nvm, after a lot of tinkering, I got it:
PHP Code:

#Check if user has an adoptable at least lvl 10
$mysidia Registry::get("mysidia");
$req_lvl 10;
$stmt $mysidia->db->select("owned_adoptables", array("currentlevel"), "owner='{$mysidia->user->username}'");
if (
$stmt >= $req_lvl) {  
    
$msg "You have a lvl {$req_lvl}{$mysidia->user->username}? Awesome!";
}
else {
    
$msg "{$mysidia->user->username}, you do not have a lvl {$req_lvl}.";


But while I'm here, any way I can get the name of said strongest adoptable?

IntoRain 11-10-2014 08:50 PM

You can actually put your condition inside the query

$count = $mysidia->db->select("owned_adoptables", array("aid"), "owner='{$mysidia->user->username}' and currentlevel >= {$req_lvl}")->rowCount();

That will return how many rows there are with that information. So if user doesn't have an adoptable with that minimum level, it returns 0

$theOne = $mysidia->db->select("owned_adoptables", array(), "owner='{$mysidia->user->username}' and currentlevel >= {$req_lvl} limit 1")->fetchObject();

This will return the whole row. I limited it by one because it might have more than one at max level. So you can access their information now with stuff like:

$hisName = $theOne->name;

Kyttias 11-10-2014 11:55 PM

Much more efficient, thanks so much! Originally, I had something similar to the first query statement you made, but it was missing the rowCount function. The sooner I get comfortable with these database queries, the better. ^^;


All times are GMT -5. The time now is 01:38 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.