supermerc Posted February 25, 2009 Share Posted February 25, 2009 Hey, I have a table where it shows each items deposited in vault by a member, and what I want to do is if he deposited 5 specific items on the same date, does something, if not, does nothing. Anyone can tell me how I can do that? Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/ Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 SELECT count(itemid) as itemcnt, `date` FROM table_name GROUP BY `date` Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771164 Share on other sites More sharing options...
supermerc Posted February 25, 2009 Author Share Posted February 25, 2009 I dont really understand the first part count(itemid) as itemcnt Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771173 Share on other sites More sharing options...
blintas Posted February 25, 2009 Share Posted February 25, 2009 using the count(itemid) as itemcnt lets you pull it as a variable from your mysql_fetch_assoc $query = mysql_query("SELECT count(itemid) as itemcnt, `date` FROM table_name GROUP BY `date`"); $row = mysql_fetch_assoc($query); print $row['itemcnt']; will give you the count. Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771177 Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 You posted no relevant code or information. You asked that a member deposited 5 items, I am taking it that you have a table of items which is linked to a member by a member id (I need to amend this). The table should have a primary key of "id" (I used itemid to hopefully paint the picture/give you the idea). The as will assign it to the returned array from mysql_fetch_assoc function as $fetchedData['itemcnt']. To do this by member: SELECT count(itemid) as itemcnt, `date` FROM table_name WHERE memberid = '2' GROUP BY `date` Or for all members: SELECT count(itemid) as itemcnt, `date`, memberid FROM table_name GROUP BY `date`, memberid But yea, provide us with code you have tried or current code and you will get far better and much more detailed help. Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771184 Share on other sites More sharing options...
supermerc Posted February 25, 2009 Author Share Posted February 25, 2009 Im not looking for a count tho, thats the thing, this is what I want If username deposited holy potion, arcane potion, fire potion, shadow potion, kinetic potion all on same date SOMETHING else nothing. Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771186 Share on other sites More sharing options...
supermerc Posted February 25, 2009 Author Share Posted February 25, 2009 I work with name not id Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771189 Share on other sites More sharing options...
premiso Posted February 25, 2009 Share Posted February 25, 2009 I work with name not id Well replace the itemid with name. Although this is a poor design for a DB (not 3NF form) that should work. Like I said, I was just trying to paint a picture, you not providing us with code etc is like hte blind leading the blind. You asked howto, I explained it. You never said, "Here is how my DB is setup here is some code I tried can anyone help me modify the code to work." It was more or less, "Can this be done if so how". Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771191 Share on other sites More sharing options...
supermerc Posted February 25, 2009 Author Share Posted February 25, 2009 Alright let my try again. What my whole script does is It logs in to a game using curl and checks the action log, if an item was awarded or deposited by a member it logs in my table called actionlog which is set up like this id (unique id for every entry) name (name of player involved) action (deposited or awarded) item (name of the item example Holy Potion) itemid (the unique id for each item) date (date which it was deposited or awarded) awarder (if item was awarded, by who) apsvalue (the amount of points given to member for depositing that item) Now what I want to do is on a different page im starting with a query that checks everything in actionlog where name = session username and what I want to do is check if the user has deposited a Holy Potion and a Arcane Potion and a Shadow Potion and a Fire potion AND a kinetic potion all on the same day, and if so then something, if not then nothing. Hope Im a bit more clear. Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771197 Share on other sites More sharing options...
sasa Posted February 25, 2009 Share Posted February 25, 2009 try SELECT name FROM `actionlog` WHERE item IN ('holy potion', 'arcane potion', 'fire potion', 'shadow potion', 'kinetic potion') GROUP BY name, `date` HAVING COUNT(id)=5 Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771208 Share on other sites More sharing options...
supermerc Posted February 25, 2009 Author Share Posted February 25, 2009 Okay ill try that, can you explain the HAVING COUNT (id)=5 thats the only part i dont understand Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771209 Share on other sites More sharing options...
sasa Posted February 25, 2009 Share Posted February 25, 2009 it mean thet member have 5 record with item in ('holy potion', 'arcane potion', 'fire potion', 'shadow potion', 'kinetic potion') 5 of 5 if member can have more then one same items in same day (2 holy potion in one day) change to 'HAVING COUNT(DISTINCT item) = 5' Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771221 Share on other sites More sharing options...
supermerc Posted February 25, 2009 Author Share Posted February 25, 2009 okay and by the way it doesnt work, Like i tested for a bunch of things and it worked I added a code to tell me if it matched or not if($selaps >0) { echo 'yes'; }else{ echo 'no'; } And What i did is I inserted values in database to test If they have 4 potion is says no if it wasnt on same day it says no, if they have holy arcane fire shadow and kinetic it says yes HOWEVER if he has holy, holy, shadow, arcane and kinetic it says yes but theres no fire. Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771230 Share on other sites More sharing options...
sasa Posted February 25, 2009 Share Posted February 25, 2009 are you change HAVING COUNT(id)=5 to HAVING COUNT(DISTINCT item) = 5 Quote Link to comment https://forums.phpfreaks.com/topic/146882-php-check-for-values/#findComment-771254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.