Jump to content

[SOLVED] if($check == 1) help


chinclub

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.