Jump to content

Recommended Posts

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?

 

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.

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.