Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/53580-solved-ifcheck-1-help/
Share on other sites

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!!!';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53580-solved-ifcheck-1-help/#findComment-264820
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.