View Full Version : Resolved Checking if a row contains specific somethings!
2Pacalypse
05-17-2009, 02:52 PM
Hey all
Was wondering, how do I check if for example a user has a particular item:
userid itemid quantity
1 19 5
1 16 1
All I want to do is check if userid 1 has itemid 19 or not.
How can I do this, please?
Thanks you!
nullpointer
05-17-2009, 02:57 PM
are you going to be calling this from php or directly in mysql with phpmyadmin? i'll assume you're calling from php.
i don't know what your table name is so i used table_name
$sql = " SELECT * from `table_name` WHERE `userid` =1 AND `itemid`= 19 ";
$result = mysql_query($sql);
if(mysql_num_rows()>0) //found it
echo 'userid 1 has item 19;
oesxyl
05-17-2009, 02:59 PM
Hey all
Was wondering, how do I check if for example a user has a particular item:
userid itemid quantity
1 19 5
1 16 1
All I want to do is check if userid 1 has itemid 19 or not.
How can I do this, please?
Thanks you!
select count(*) from yourtablename where userid = 1 and itemid = 19
will return the number of rows that match the condition.
sorry nullpointer, I didn't see your answer
best regards
2Pacalypse
05-17-2009, 03:11 PM
Thanks
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.