2

I'm creating a pricing array jQuery and for this project the amount of different products I need is going to be +200 so the easiest option I could research would be listing from a SQL table.

This is what I have so far:

        $(document).ready(function() {
            /*** CONSTANTS ***/
            var KEY = 0;
            var VALUE = 1;
            /*** DEFINE DATA SETS ***/
            var POINTS = [ ["250", 46.5 ], ["500", 53.5], ["1000", 67], ["2500", 107.5], ["5000", 175], ["10000", 310] ];
            var SHIPPING_COSTS = [ ["Pickup", 0], ["Next Day Delivery", 30], ["Same Day Print/Same Day Delivery", 65] ];

            for (var i = 0; i < POINTS.length; i++) {
                $("#quantity").append("<option value='" + POINTS[i][VALUE] + "'>" + POINTS[i][KEY] + "</option>");
            }
            for (var i = 0; i < SHIPPING_COSTS.length; i++) {
                $("#shipping").append("<option value='" + SHIPPING_COSTS[i][VALUE] + "'>" + SHIPPING_COSTS[i][KEY] + "</option>");
            }

            $("select.autoUpdatePrice, input.autoUpdatePrice").bind("mousedown click change", function(event) {
                Calculate();
            });
            Calculate();    
        });


    function Calculate() {
        var net = parseFloat($("#quantity").val());
        /* Calculate the magical # by adding the form fields*/
        var designFee = $("#abcDesignFee").attr("checked") ? $("#abcDesignFee").val() : 0.0;
        var proofFee = $("#abcProofFee").attr("checked") ? $("#abcProofFee").val() : 0.0;
        var MyPrice;
        MyPrice = parseFloat( parseFloat(proofFee) + parseFloat(designFee) + net + parseFloat($("#shipping").val()));
        $("#DumpHere").html("Your Price: $" + formatNumber(MyPrice));
        $("#abcName").val($("#quantity").find(":selected").text() + " " + ProductNamePlural);
        $("#abcPrice").val(MyPrice);
    }

1 Answer 1

3

Create a PHP file and read the data from SQL into an array. Print that array after json_encode(). Then use jQuery.getJSON() on document ready to fetch it and process it.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your response, any chance you could maybe help me in the right direction for printing sql data into an array? I've looked, and am lost.
@David When you use mysql_fetch_array in a loop, you get it in an array form. Create a new array and push the data required into it with array_push or [] operator. If you start a new question regarding this, you will get better help.
I wound up getting the json_encode to work, thank you, now I am working on getting it into my javascript! Thank you again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.