Difficult one

Post here if you need help with SQL.
Post Reply
jeowd
Posts: 5
Joined: Sat Aug 20, 2011 1:26 am

Difficult one

Post by jeowd »

I am working on a Minecraft website project. I have a table in the database with the in game data value for blocks(only ones that cannot be crafted). I want to have a separate table for those which can be crafted in to things like Pistons. How would I be able to do a query where it will return all craft recipes that have cobblestone as an example? I was thinking of an array but unsure how it would work :?

Thanks
Torniquet
Posts: 52
Joined: Sun Jun 19, 2011 8:10 am
Contact:

Re: Difficult one

Post by Torniquet »

How is the table layed out?

if all materials needed are in a single field then use like and the wildcard
SELECT * FROM recepies WHERE materials LIKE "%cobblestone%"
if each material has its own field then you could do something like
SELECT * FROM recepies WHERE material_1 = "cobblestone" OR material_2 = "cobblestone" etc....
Thats how i would query it, but no doubt there is a better way lol.
Last edited by jacek on Thu Sep 08, 2011 11:11 pm, edited 1 time in total.
Reason: code tags...
jeowd
Posts: 5
Joined: Sat Aug 20, 2011 1:26 am

Re: Difficult one

Post by jeowd »

Torniquet wrote:How is the table layed out?

if all materials needed are in a single field then use like and the wildcard

SELECT * FROM recepies WHERE materials LIKE "%cobblestone%"


if each material has its own field then you could do something like

SELECT * FROM recepies WHERE material_1 = "cobblestone" OR material_2 = "cobblestone" etc....


Thats how i would query it, but no doubt there is a better way lol.

Thanks, but what happens if someone queries stone and it returns cobblestone. I'm sure there will be a way to do it more specific :?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Difficult one

Post by jacek »

Can you post your table structure ?
Image
Post Reply