wrybread Posted December 3 Share Posted December 3 I have a PHP page drawing multiple items, each in a single row, and currently each makes a separate MySQL query, and now that the database is huge, this is really slow. For example, if it was a page showing different kinds of pastries we have available, I'm drawing the page like this: [get details about croissants: SELECT * FROM `descriptions` WHERE `item` LIKE 'croissant' LIMIT 1;] [draw a picture of a croissant with details obtained from DB] --------------- [get details about baguettes: SELECT * FROM `descriptions` WHERE `item` LIKE 'baguettes' LIMIT 1;] [draw a picture of a baguette with details obtained from DB] --------------- [get details about rolls: SELECT * FROM `descriptions` WHERE `item` LIKE 'rolls' LIMIT 1;] [draw a picture of a rolls with details obtained from DB] There's 40 items on each page, and it now takes about 5 seconds to load the page. I'm wondering if there's some clever way to query the DB one time at the top of the page with all my queries? Something like this pseudo code: SELECT * FROM `descriptions` WHERE `item` LIKE 'croissant' OR `item` LIKE 'baguettes' OR `item` LIKE 'rolls'; and then iterate through the results? Quote Link to comment https://forums.phpfreaks.com/topic/326031-possible-to-have-a-single-mysql-query-for-multiple-items/ Share on other sites More sharing options...
wrybread Posted December 3 Author Share Posted December 3 Nevermind, as is probably obvious from the question I'm an idiot. Solved. Quote Link to comment https://forums.phpfreaks.com/topic/326031-possible-to-have-a-single-mysql-query-for-multiple-items/#findComment-1645041 Share on other sites More sharing options...
mac_gyver Posted December 3 Share Posted December 3 you should have a category table, with id and name columns. this would define the different categories of items. the item table would have id, category_id, name, description, and any other columns needed to define each item. to display the category menu you would query the category table to get the category data that you want in the order that you want it, then loop over the result of this query to produce the category menu. if someone clicks on one of the category menu links, the category id in the link would be used to query for and display the items matching that category. Quote Link to comment https://forums.phpfreaks.com/topic/326031-possible-to-have-a-single-mysql-query-for-multiple-items/#findComment-1645044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.