chinclub Posted May 30, 2007 Share Posted May 30, 2007 I am writing a script where I want it to check for several items in the database. If any one of those items isn't there I want it to give an error. If all items are there I was it to go to the next page. I have done one step checks before but never multiple. I have it set like this: $check = mysql_num_rows(mysql_query("SELECT * FROM `items` WHERE `user`='{$_COOKIE['ipets']}' AND `name`='baby safe cage' AND `equipped`='1'")); $checkaid = mysql_num_rows(mysql_query("SELECT * FROM `items` WHERE `user`='{$_COOKIE['ipets']}' AND `name`='first aid kit' AND `equipped`='1'")); $checksup = mysql_num_rows(mysql_query("SELECT * FROM `items` WHERE `user`='{$_COOKIE['ipets']}' AND `name`='Supplement kit' AND `equipped`='1'")); $checksvet = mysql_num_rows(mysql_query("SELECT * FROM `items` WHERE `user`='{$_COOKIE['ipets']}' AND `name`='vet directory' AND `equipped`='1'")); but I am not sure how to write the next line. Would I write all checks together like this: if($check == 1 && $checkaid == 1 && $checksup == 1 && $checksvet == 1) or am I totally wrong all together on this? Quote Link to comment https://forums.phpfreaks.com/topic/53580-solved-ifcheck-1-help/ Share on other sites More sharing options...
chigley Posted May 30, 2007 Share Posted May 30, 2007 Yes your if statement looks fine, why not try it before asking!? Quote Link to comment https://forums.phpfreaks.com/topic/53580-solved-ifcheck-1-help/#findComment-264819 Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 Why use 4 separate queries? <?php $check = mysql_num_rows(mysql_query("SELECT * FROM `items` WHERE `user`='{$_COOKIE['ipets']}' AND `name` IN('baby safe cage','first aid kit','Supplement kit','vet directory') AND `equipped`='1'")); if ($check < 1) { die('None of the items were found'); }else { echo 'Yay we found ' . $check . ' number of items!!!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53580-solved-ifcheck-1-help/#findComment-264820 Share on other sites More sharing options...
chinclub Posted May 30, 2007 Author Share Posted May 30, 2007 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/53580-solved-ifcheck-1-help/#findComment-264834 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.