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 8440483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:18:23+00:00 2026-06-10T08:18:23+00:00

I am creating a website that stores recipes. I am wanting to make a

  • 0

I am creating a website that stores recipes. I am wanting to make a recipe scaler-where you can enter the desired servings, and the script will convert the recipe ingredients to match it. I can change the amount easy enough, but I’m trying to figure out how to convert units. Now I know I can go and put in 1500 if/then statements, but I’m trying to make it a bit simpler. 🙂

I was looking at a site called Tasty Kitchen. They POST the servings via AJAX to this file (http://tastykitchen.com/recipes/wp-admin/admin-ajax.php), and that file returns the ingredients. Then they display them on the page. Go to http://tastykitchen.com/recipes/breads/plain-bagels/ for an example.

I would REALLY appreciate any help I can get.

Thanks!

  • 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-06-10T08:18:24+00:00Added an answer on June 10, 2026 at 8:18 am

    My suggestion would be to store a single serve in your database, then simply multiply out how many people you want to feed on the page.

    So, if your user has selected they want to make the meal for 4 people, you keep a variable (session, cookie, whatever) – lets call it $peeps for this example – when you output the data you do soemthing like this:

    Echo "This will make $peeps portions:";
    Echo "Ingredients:<br>";
    Echo ($peeps*Ingredient1Quantity)." - ".$ingredient1Name."<br>";
    Echo ($peeps*Ingredient2Quantity)." - ".$ingredient2Name."<br>";
    

    and so on.

    If you want your site to also convert from imperial to metric, you can do it easily enough with a simple function.

    If you store all your data in metric in the database (or Imperial, but all the same type) you can output it easily enough by converting it in a similar manner to the user based on their preference:

    // Assumes a function that converts to Imperial from Metric called convertToImperial()
    Echo "This will make $peeps portions:";v
    Echo "Ingredients:<br>";
    Echo convertToImperial($peeps*Ingredient1Quantity)." - ".$ingredient1Name."<br>";
    Echo convertToImperial($peeps*Ingredient2Quantity)." - ".$ingredient2Name."<br>";
    

    Edit: If you store everything in the database in Metric, you can then have a function return the data to you in the best Imperial measurement.

    // For example, input is passed as 
    // $qty=30 (ml) 
    // $serves is passed as 3 (ie, three people)
    // $type is passed as liquid.
    
    function convertToImperial($qty, $serves, $type)
    {
        // Metric to Imperial will need a $type passed (Liquid, Weight, Other).
        // You can use a switch statement to pass between the different types.
        switch ($type)
        {
             case "Liquid":
                 // Assumes 5ml is a teaspoon
                 // Assumes 15ml is a tablespoon
                 // Assumes 250ml is a cup.
                 $CalMeasure=$qty*$serves; // Now at 90ml.
                 // Here you can now choose to either pick the best match
                 // ie, measurement with least remainder/exact measure
                 // which in this case would be 6 tablespoons
                 // or
                 // switch measurement types after a certain quantity is reached.
                 if ($CalMeasure>125) // Half a cup
                 {
                     return (round($CalMeasure/250,2)." cups");
                 }
                 elseif ($CalMeasure>15) // tablespoons
                 {
                     return (round($CalMeasure/15,2)." Tablespoons");
                 }
                 else
                 {
                     return (round($CalMeasure/5,2)." Teaspoons");
                 }
                 break;
             case "Weight":
                 // Similar approach to Weights, Convert Grams to Pounds and the like.
                 return $WeightMeasured;
                 break;
             default: // assumes Other (pinches, sprinkles etc
                 // Similar approach again.
                 break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a website that will allow people to make lists, but I'm
I'm creating a mobile website that will include a page from which people can
I am creating a website that will be used by an accounting dept. to
i'm creating a shopping website that will sell computer parts using MVP and asp.net.
I am creating a website that will have articles; each article will have comments.
I'm creating a website that will feature news articles. These articles will appear in
I am creating a website that uses W3C Geolocation API and position.timestamp for timestamp.
I am creating a website that uses a fluid layout with artificial columns. I
I'm creating a website that has both commenting and voting systems. I wanted to
I am creating an part of a website that deals with confirmation of a

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.