Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6873567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:05:06+00:00 2026-05-27T04:05:06+00:00

I have a ingredient mysql database. I let the user save to their profile

  • 0

I have a ingredient mysql database. I let the user save to their profile home cabinet what ingredient per category they select. I have 10 categories, so I will be making 10 queries per profile. My query is setup like so:

select I.Iname, I.Ipic, I.IID, I.ICat 
from Ingredient I 
left outer join Cabinet C on I.IID = C.IId 
where Login.LoginID='{$_COOKIE['login']}' and I.ICategory ='fruit'; 

— is ran 10 times since i have 10 different categories

–for each row returned it outputs divs under the specific category header.

Now my question is there a more optimized way of doing this as to storing their cabinet data in session objects, arrays or using a cookie? Or is running 10 of these queries not that much of a performance impact. What if someone is returning 100 rows for each category? Or should I just query all categories and loop through the result to place each row in its specific area.

cabinet table :

loginID | ingredientID 
----------------------
   1    |     3 
   1    |     4 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:05:07+00:00Added an answer on May 27, 2026 at 4:05 am

    You have 2 possible choices:

    1. Leave everything as is. There is nothing wrong with SQL queries per se. A database is not something necessary slow and hulky. It is just a storage, as well as a session file (which can be in turn stored in the database, so, you’ll end up in the same point but make things unnecessary complicated!). Databases intended to e queried! It is the only their destination! And they are smart enough even to cache your results.
      Note that storing mysql results in cookie is not an option at all, under any circumstances, it will slow your site for sure. (It seems it always needs to be clarified that there is nothing wrong with cookies as well. it is just not intended to cache data)

    2. Implement some Model in terms of MVC pattern and make all data requests abstract. So, you will be able to implement any caching techniques later, without altering other program code.

    Also note, that no performance-wise question asked on the grounds of wild guess can make sense.
    See, you were about to make even worse (using cookies), out of some grounndless assumption.
    Always ask yourself about performance only if there is a certain problem to solve. Otherwise you will most likely just miss the point or even do things worse.

    Update
    After seeing your query I can say that there is no need to do 10 queries, – one is enough. Just order it by ingredient and then add divs dynamically in PHP. (If you have no idea how to do it, better create another question, to make things do not interfere)

    And of course you have to escape your $_COOKIE[‘login’] if you don’t do it already.

    $cookie = mysql_real_escape_string($_COOKIE['login']);
    

    and use that $cookie variable in the query.

    Also note that using just cookied login will make your site extremely weak in term of security – anyone will be able to login under someone else’s account.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi all i have a field ammount in mysql database which have varchar(50) type.
I have begun creating a wpf mvvm app. It seems a vital ingredient to
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
I have a core data recipe object that contains an ordered list of ingredient
I'm doing a project about cooking recipes with PHP(with Codeigniter) and MYSQL. I have
Another newbie question. The goal: each ingredient can have zero or more unit conversions
I have 2 tables : Ingredients with the following fields: ID (numeric) Ingredient (text)
I have a simple php structures. class Ingredient and class Ingredients, i have this
Complete rails newbie trying to get started. I have two classes, Ingredient, and Unit.
I'm making a cocktail database, and right now I have three tables: drinks has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.