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

  • SEARCH
  • Home
  • 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 8609035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:46:25+00:00 2026-06-12T03:46:25+00:00

Here’s my problem: I’m making a crafting system for a game, and I already

  • 0

Here’s my problem: I’m making a crafting system for a game, and I already have my database filled with information for resources required to craft items.

Here are what my relevant tables look like:

table #edible_resources
(edible_resource_id, edible_resource_name, hunger_points, degeneration_id)

table #edible_ground
(id, resource, amount, location)

table #req_crafting_edible
(req_crafting_edible_id, edible_resource_id, req_resource_amount, created_item_id)

table #items
(item_id, item_name, degeneration_id, is_grounded, is_stackable, can_equip, can_edit)

What I want to do is -only- echo out the craftable item’s name if, and only if -all- required resources (and their required amounts) are on the ground in the location of the character.

I have a query that comes close:

SELECT items.item_name, items.item_id FROM items
INNER JOIN req_crafting_edible
ON req_crafting_edible.created_item_id = items.item_id
INNER JOIN edible_ground
ON edible_ground.resource = req_crafting_edible.edible_resource_id
AND edible_ground.amount >= req_crafting_edible.req_resource_amount
WHERE edible_ground.location = $current_location
GROUP BY items.item_name
ORDER BY items.item_name

But this shows me craftable items regardless if I have ALL the required items in the area. It shows me items as long as I have -one- of their required resources.

Is there a way to only show the name of a craftable item only if I have -all- the required resources (and their amounts) in edible_ground where location = $current_location?

For more information on what I’ve tried:

$get_char = mysql_query("SELECT current_char FROM accounts WHERE account_id ='".$_SESSION['user_id']."'");
$current_char = mysql_result($get_char, 0, 'current_char');

$get_loc = mysql_query("SELECT current_location FROM characters WHERE character_id = $current_char");
$current_location = mysql_result($get_loc, 0, 'current_location');

//---------------------------------------------------------------COOKED FOOD
$get_food = mysql_query("SELECT items.item_name, items.item_id FROM items
INNER JOIN req_crafting_edible
ON req_crafting_edible.created_item_id = items.item_id
INNER JOIN edible_ground
ON edible_ground.resource = req_crafting_edible.edible_resource_id
AND edible_ground.amount >= req_crafting_edible.req_resource_amount
WHERE edible_ground.location = $current_location
GROUP BY items.item_name
ORDER BY items.item_name");
while ($food = mysql_fetch_array($get_food)){
  echo $food['item_name'].'<br>';
}

This returns:

  • Baked Fish
  • Charred Fish
  • Fish Soup
  • Glazed Berry
  • Cake
  • Grilled Fish
  • Sashimi
  • Seafood Soup
  • Sushi
  • Udon

On the ground:

  • 1 fish
  • 1 honey

Even though fish soup, berry cake, udon etc needs much more than just the one fish that’s in the area.

Can anyone help me figure this out? I’d be forever grateful; I’ve spent a few days already trying to myself. Please?

And before anyone says anything, I know I need to start using mysqli; unfortunately I didn’t even realize it existed when I started to make the game (and learn PHP at the same time months ago), so I’ll have to painfully go back and change it all in an update.

  • 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-06-12T03:46:26+00:00Added an answer on June 12, 2026 at 3:46 am

    You want a HAVING clause to check the count of the records you are grouping through the INNER JOINs.

    HAVING count(*) = (
      SELECT count(*)
        FROM req_crafting_edible
        WHERE req_crafting_edible.created_item_id = items.item_id
    )
    

    Edit:

    So basically you need to know two pieces of information:

    • How many different resources are required
    • Do each of those resources have the required amounts

    The first is solved by the sub query above.

    Your query as-is satisfies the second point but only for 1 resource.

    HAVING basically does some special magic on your group clause. HAVING count(*) means there are X records being grouped together. Because of how the join works, you will have 1 item.name for each resource. The sub select gives you the count of how many different resources, and therefore grouped records, are needed for that item. Comparing that sub query with the count(*) of the grouping ensures you have all the needed resources.

    And here is the final query, modifying your code above:

    SELECT items.item_name, items.item_id
      FROM items
        INNER JOIN req_crafting_edible
          ON req_crafting_edible.created_item_id = items.item_id
        INNER JOIN edible_ground
          ON edible_ground.resource = req_crafting_edible.edible_resource_id
            AND edible_ground.amount >= req_crafting_edible.req_resource_amount
      WHERE edible_ground.location = $current_location
      GROUP BY items.item_name
      HAVING count(*) = (
        SELECT count(*)
          FROM req_crafting_edible
          WHERE req_crafting_edible.created_item_id = items.item_id
      )
      ORDER BY items.item_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the problem I'm trying to solve for my game. I have this
Here is the problem that I am trying to solve. I have two folders
Here is my problem : I have a post controller with the action create.
Here is my problem.. I have the option to create(add) two new input fields,
Here's the code I have. It works. The only problem is that the first
Here's a problem I ran into recently. I have attributes strings of the form
Here is the problem. I have <div id=main></div> I want to check user resolution
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the two scripts I have Script 1: <? include('config.php'); $json = $_POST['payload'];
Here my problem: @Assert\Regex( * pattern=/^[A-Za-z0-9][A-Za-z0-9\]*$/, * groups={creation, creation_logged} * ) I'm using the

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.