Results 1 to 5 of 5

Thread: Automatic Reverse Auction Style Pricing

  1. #1
    Join Date
    Apr 2010
    Location
    West Sussex, England
    Posts
    5
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Automatic Reverse Auction Style Pricing

    I am a PHP novice. Could you please help me with this script!

    • I am trying to create an automatic reverse auction, whereby the price reduces by a set amount each day!
    • The price will start high and reduce by a set amount each day.
    • The start price, start date and reduction amount values will all be assigned by me and entered into a database as fixed ‘variables’. The only true variable ‘variable’ will be the Date, which will change on a daily basis.
    • PHP will use the information in the database, and the actual Date, to calculate and display the price each day on the website.
    • I think the formula will be (StartPrice – ((Date – StartDate) x ReductionAmount))
    • The reduction will occur at the same time each day, when the Date officially changes, and will stay at the new lower price for the rest of the day.
    • Another reduction will occur the next day etc.
    • There will only be one instance of ‘bidding’ – when someone buys the item.
    • If the item does not sell before it reaches the reduction amount, it will be withdrawn.

    Having watched the price for this item reduce on a regular daily basis, someone decides on a particular day they can afford to buy the item on offer at the price displayed on that day (rather than wait for the price to reduce further at the risk of losing the item to someone else with a deeper pocket!). They add the item to the cart and pay for it at the checkout. The sale is over and the item is removed from the website.

    I hope this explains what I am trying to achieve! If, for example, I assign the values:

    StartDate=Apr 3 2010
    StartPrice=5000
    ReductionAmount=50

    then hopefully, using PHP, StartPrice – ((Date – StartDate) x ReductionAmount)) will produce the following:

    • On April 4, 2010 the website showed “Price today is $4950

    • On April 5, 2010 the website shows “Price today is $4900

    • On April 6, 2010 the website will show “Price today is $4850

    etc ...

    Thank you for your help.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You might be better off putting this in the "General Paid Work Requests" since this is quite a lot to do for free.

    I doubt someone is willing to make this whole system for you unless you are willing to offer something in return, unless you already have parts of the system in place and need help with certain parts of it.

    Good luck.

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This is very easy to setup in a basic sense.
    Code:
    <?php
    $date = '[timestart]';
    $dailychange = '50';
    $startprice = '1000';
    $days = round((time()-$date)/60*60*24);
    echo $startprice-$days*$dailychange;
    ?>
    Of course this doesn't deal with things like what happens when the item now costs $0, etc.

    You may want to put this in paid work requests (in fact I might be able to help, depending on the complexity, time required, deadline, etc.), or it might even be possible to solve it here.

    What we need to know is exactly how complex you want this.

    If you want an admin system where you can enter days on a calendar and add products to a database, that's an entirely different issue. If you JUST want the math component, then in theory the code I have about jsut about covers it (with a bit of setup into your page). If you want something in between, describe exactly what features you want, (how much you are willing to pay if you choose to post this as a paid work request), and anything else that might be relevant.

    In fact if you want to move this to be a paid request, just make a note of it in your next post. If you don't, we may still be able to help you but in that case it's usually a do-it-yourself with our help approach.



    By the way, I'm glad you decided to approach this with PHP. Though it's a little more of a 'serious' language and requires more setup, there's a lot more you can do with it than with Javascript alone.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. The Following User Says Thank You to djr33 For This Useful Post:

    StephenGeorge (04-07-2010)

  5. #4
    Join Date
    Apr 2010
    Location
    West Sussex, England
    Posts
    5
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Thanks once again djr33! I seem to be getting somewhere now!!!

    Code:
    <?php
    $startprice=7500;
    $dailychange=25;
    $first_date=mktime(12,0,0,1,16,2010);
    
    $second_date=mktime(12,0,0,4,4,2010);
    $days=$second_date-$first_date;
    
    echo "This sale started on " . $first_date . "<br />";
    echo "Today's date is " . $second_date . "<br />";
    echo "Sale start price was $" . $startprice . "<br />";
    echo "Daily reduction amount is $" . $dailychange . "<br />";
    echo "Number of days since sale started is " . $days/(60*60*24) . "<br />";
    echo "The price today is $" . ($startprice-(($days*$dailychange)/(60*60*24)));
    ?>
    The above produces the desired result, but not every time! For instance, using Jan 16, 2010 as the First Date and Mar 4, 2010 as Second Date, I get this result:

    This sale started on 1263643200
    Today's date is 1267704000
    Sale start price was $7500
    Daily reduction amount is $25
    Number of days since sale started is 47
    The price today is $6325


    However, if I use same First Date and Apr 4, 2010 as Second Date, I get this result:

    This sale started on 1263643200
    Today's date is 1270378800
    Sale start price was $7500
    Daily reduction amount is $25
    Number of days since sale started is 77.958333333333
    The price today is $5551.0416666667


    My ‘days’ figure is out by 0.0416666667, or 1/24th. How can I ensure the ‘number of days’ figure is a full integer. I have tried ‘ceil’ and ‘round’, without luck?

    My ultimate goal is for the ‘second_date’ variable to be automatic, ie the actual date at the time that the page is served.

    Of course, the last line is the one that will be displayed on the website, but I have shown them here just to help with producing the script.

  6. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. round(FULL_NUMBER_STATEMENT).
    Just put the whole numerical/mathematical expression inside parentheses and you'll get an integer.
    round() goes to the closest whole number.
    ceil() goes up to the next highest whole number (or stays if it is a whole number).
    floor() goes down to the next highest whole number (or stays if it is a whole number).
    In this case, I think you probably want floor($days/(60*60*24)).

    2. mktime() is actually the complex version. That makes a timestamp from date input. For the current server time, use the function time()
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. The Following User Says Thank You to djr33 For This Useful Post:

    StephenGeorge (04-08-2010)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •