Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2014, 01:01 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,312
Kyttias is on a distinguished road
Default 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?
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 11-10-2014 at 07:31 PM.
Reply With Quote
  #2  
Old 11-10-2014, 08:50 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,374
IntoRain is on a distinguished road
Default

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;
__________________


asp.net stole my soul.

Last edited by IntoRain; 11-10-2014 at 09:09 PM.
Reply With Quote
  #3  
Old 11-10-2014, 11:55 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,312
Kyttias is on a distinguished road
Default

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. ^^;
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a "Faction" for adoptables/owned adoptables Vaporman87 Questions and Supports 1 03-04-2014 03:38 PM
Doesnt go to owned adopt database keliptis Questions and Supports 0 02-12-2012 06:47 PM
Adopt pages, and general adopt/index page :L blondbananamix Questions and Supports 26 07-22-2011 12:12 PM
Create/Edit/Delete user's owned adoptables through acp! Hall of Famer Mys v1.1.x Mods 7 01-24-2011 02:45 PM
2 - column on Adopt page and my Adopt page? SieghartZeke Questions and Supports 2 10-12-2009 02:58 PM


All times are GMT -5. The time now is 05:27 AM.

Currently Active Users: 9724 (0 members and 9724 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636