Jump to content

wrybread

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by wrybread

  1. Nevermind, as is probably obvious from the question I'm an idiot. Solved.
  2. 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?
  3. What would be the disadvantage of having a column in the main table named "categories" and having a string value for all the categories an element belong to? For example, the value could be "blue yellow purple orange" etc. I guess the disadvantage is that it's slower to find all elements that are blue?
  4. I'm working on a form processed by PHP where multiple categories are saved to a MySQL table. Currently I have one table column for each category. For example I have a column in my table for "is_category1", and a column for "is_category2", and one for "is_category3", etc. (Those aren't the real column names, that's just for simplicity). The problem is that we keep adding new categories, and I'd rather not add a new column every time we do. So I was thinking I could store the categories as a single string in a column called "categories" and have a character for each category. For example if the string is "100" it would mean is_category1=true, is_category2=false and is_category3=false. That all works very well. The problem is that I don't see a good way to perform searches. For example if I want to find every item where is_category2==true, I don't know of a SQL query to do that without iterating through each item in the table and processing the "categories" string. And there are over 50,000 items in the table, so that would be unacceptably slow. Does anyone happen to have any advice about how to handle this? Maybe there's a SQL search method that can process the Xth item of a string? Or a better way to store the "categories" item than a string? Or am I just doomed to have a table column for every category? Thanks for any help.
×
×
  • 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.