Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:28:32+00:00 2026-05-23T04:28:32+00:00

Im trying to come up with some code to check whether or not a

  • 0

Im trying to come up with some code to check whether or not a user owns a list of items. The list of items can be any length but will probably be no more than 5.

There are 2 tables involved here: qrequirements and inventory.

I’ve got as far as running a loop to check a user has each item, but I’m stuck on how to record the result of the ownership of each item and how this can be communicated to the user afterwards.

I might be going about all this the wrong way and maybe there’s a simpler way, I don’t know.

Any help would be great. Here’s my code so far:

<?php

// Get the list of required items
$result = mysql_query("select * from qrequirements where qid='2'");
// This might return E.G:
// item1 = '32'
// item2 = '24'
// item3 = '15'

// Loop through each item to check the user has it
while ($row = mysql_fetch_array($result)) {
    $itemid = $row["itemid"];
    $check_inv = mysql_query("select * from inventory where userid='$userid' AND item = $itemid");
    $num_rows = mysql_num_rows($check_inv);
    if($num_rows>=1){
        // Something in here to confirm the item is owned by the user, while we check the others
    }else{
        echo "You do not have this item";
    }
}

// Notify the user if they have all items required

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:28:33+00:00Added an answer on May 23, 2026 at 4:28 am

    Determining the items that a user needs but does not have can be solved by a single query. The below query should accomplish that task.

    SELECT * FROM qrequirements t1
     WHERE t1.quid = '2'
       AND NOT EXISTS ( SELECT 1 FROM inventory t2
                     WHERE t1.item = t2.item
                       AND t2.userid = '$userid')
    

    If you also need to know which items the user does have then this similar query will accomplish that additional task.

    SELECT * FROM qrequirements t1
     WHERE t1.quid = '2'
       AND EXISTS ( SELECT 1 FROM inventory t2
                     WHERE t1.item = t2.item
                       AND t2.userid = '$userid')
    

    Another useful query is one that would return the required items and an indicator of whether the user has that item. The item_count will be 0 if the user does not have the item and greater than 0 if the user does have the item.

    SELECT t1.*, (SELECT count(*) FROM inventory t2
                   WHERE t1.item = t2.item
                     AND t2.userid = '$userid') as item_count
     FROM qrequirements t1
    WHERE t1.quid = '2'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been investigating frame breaking code recently and have come across some really bizarre
I'm trying to get some simple piece of code I found on a website
I'm trying to create a Tile rendering program. Heres some basic code. Header class
I have to work on some code that's using generic lists to store a
The project I am working on were are trying to come up with a
I'm a user of Aquamacs under OS X, which by default does not recognize
So basically I am trying to check the arguments that are passed into the
I am trying to come up with a generic way to pull an object
I am trying to parse a csv file and in the process have come
I'm converting an old AS2 file into AS3 (and trying to learn AS3 at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.