Jump to content

Recommended Posts

i have a hierarchical tier structure with folders and items. But I want each item to have the ability to be in multiple folders.

 

E.g.

 

Root

- Cafes

- - Coffee Shops

- - Takeaways

- Restaurants

- - Franchises

- Small Shops

- Stores

 

Then businesses will have multiple categories. (I.E. McDonalds might have restaurants and takeaways)

 

I've done that by creating a field within businesses called 'business_category' where it separates the multiple categories with _.

 

E.g. 12_3

 

So, the point I'm stuck on now is displaying the business within the relevant folder.

 

SELECT * FROM businesses WHERE business_category = folder_id ORDER by business_title

 

I want to explode the 12_3 into an array, then check both of them that they equal the current folderid. But the only way I can think of is to loop through the array running the query each time.

 

I know this is processor intensive so does anyone know a better way? I'm pretty confident there is one.

 

Many thanks in advance.

 

-James

Link to comment
https://forums.phpfreaks.com/topic/266756-searching-mysql-with-an-array/
Share on other sites

I know this is processor intensive so does anyone know a better way? I'm pretty confident there is one.

Indeed there is. Get rid of that column you have now and replace it with an entire table. Actually, wait to get rid of it, you'll need it to import the data into the new table (once you've done that then you can kill it off). This table has a minimum of two columns: the parent category and the child... thing. One row for each distinct pair:

parent      | child
------------+----------
Restaurants | McDonalds
Takeaways   | McDonalds

(but with ID numbers of course)

Ugh, now I'm stuck again.

 

It inserts into 'bus_parents' perfectly.

 

So I've now got:

 

bus_parent_id	| bus_parent_parent| bus_parent_child
 4	                  3	                          10
 3	                  12	                          10
 5	                  7	                          10
 6	                  6	                          10

 

bus_parent_parent = the folder id

bus_parent_child = the business id

 

Now to display it appropriately I need to get 'business_title' from 'businesses' where business_id = (then get bus_parent_child where bus_parent_parent = the current url id)

 

I presume I need to put one SELECT within another, but I'm a bit unclear how to get this and my mind is noodling as I write this.

 

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.