Jump to content

Recommended Posts

Hello there,

I want to avoid to much calls to mysql for one menu.

I have varios posts and want to arrainge them in menu categories.

 

mysql table is:

post_id
user_id
post_date
post_content
post_title
post_url
post_tags

And I could say make one more table with name categories, but I

still My call will be: Select * from post where category id = {$category I need}

And then again for the second category and third etc.

 

My question is: Is there a smarter way to do it, Becouse it is a menu and I need to make connection and call every time the other category is around.

 

Any help would be great...

tnx.

Daka

Hello there,

I want to avoid to much calls to mysql for one menu.

I have varios posts and want to arrainge them in menu categories.

 

mysql table is:

post_id
user_id
post_date
post_content
post_title
post_url
post_tags

And I could say make one more table with name categories, but I

still My call will be: Select * from post where category id = {$category I need}

And then again for the second category and third etc.

 

My question is: Is there a smarter way to do it, Becouse it is a menu and I need to make connection and call every time the other category is around.

 

Any help would be great...

tnx.

Daka

 

I suppose you could use the IN keyword like so:

 

SELECT * FROM tbl WHERE category IN ('$cat1','$cat2',etc)

 

Then load ur results in a php array. Then do a loop on the array each time you build your menu's finding entries with only the specific category to output to that section of your menu... Although I don't know why you would want to do this.

surely if it is a menu, you would be calling for a particuilar category when that menu item was selected, so you would be querying on one category at that time

 

Yes. He doesn't want to query that many times but i doubt that the php solution i presented for him is much more efficient.

tnx for replay,

I have menu with 3 category's and each category has something.

ex.

europe->amsterdam, berlin, brussel etc.

asia->bejing, bangladesh et.

 

And I don't want to call to much MySQL, I think because of preformence.

 

your solution with IN and category's I need to try it out, but if you coeld give me some oop code how to make this would be great.

many thnx

OOP doesn't really matter here. If you're using a DB object to then you'd need to provide details on how it's used, or what it's called if it's well known.

 

Are you saying you're wanting to return a category, plus it's sub-categories, without needing multiple queries?

 

 

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.