dakasadaka Posted February 24, 2010 Share Posted February 24, 2010 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 Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/ Share on other sites More sharing options...
aeroswat Posted February 24, 2010 Share Posted February 24, 2010 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. Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/#findComment-1017451 Share on other sites More sharing options...
jl5501 Posted February 24, 2010 Share Posted February 24, 2010 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 Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/#findComment-1017458 Share on other sites More sharing options...
aeroswat Posted February 24, 2010 Share Posted February 24, 2010 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. Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/#findComment-1017462 Share on other sites More sharing options...
dakasadaka Posted February 26, 2010 Author Share Posted February 26, 2010 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 Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/#findComment-1018377 Share on other sites More sharing options...
Adam Posted February 26, 2010 Share Posted February 26, 2010 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? Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/#findComment-1018383 Share on other sites More sharing options...
dakasadaka Posted February 26, 2010 Author Share Posted February 26, 2010 yes that's exacly what I want! tnx, daka Link to comment https://forums.phpfreaks.com/topic/193219-avoid-to-much-calls-to-mysql-for-one-menu/#findComment-1018413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.