Jump to content

gazzamc

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Posts posted by gazzamc

  1. Post the exact code you are using.

     

    ok here it is..

     

    
    <?php
    if (isset($_POST['slider'])) {
      $ptz = $_POST['slider'];
    
      /// Grabs user input.
      $prce = 500;
      $points = 2000;
    
      // Sets discount.
      $price = $prce;
      $dis = '0.01';
      $price2 = $price * $dis; // gets discount from price
    
      // sets percentage per x amount of ptz.
      $pts = $ptz;
      $perc1 = '100'; // above 1% = 100 ptz
      $total = $pts / $perc1; // users ptz divided by 100 ptz
      $mtotal = $price2 * $total; // discount multiplied by result above.
    
      // Subtracts discount from price.
      $ftotal = $price - $mtotal;
    
      $arr = array(
        "Points" => $points,
        "Price" => $prce,
        "Discount" => $ftotal
      );
    
      @header("Content-type: application/json");
      echo json_encode($arr);
    }
    ?>
    
    <!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" />
        </head>
        <body>
            <div id="foo">Data returned from php will show here.</div>
            <div id="scrollbar"></div>
        </body>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#scrollbar').slider({
                    value: 0,
                    slide: function(event, ui) {
                        $('#scrollbar').slider('value', ui.value);
                        $.ajax({
                            type: 'post',
                            url: '#',
                            datatype: 'json',
                            data: {'slider': ui.value},
                            success: function(fromphp) {
                                $('#foo').html("Points = " + fromphp.Points + "<br />Price = " + fromphp.Price + "<br />Discount Price = " + fromphp.Discount + "<br />");
                            }
                        });
                    }
                });
            });
        </script>
    </html>
    
    

  2. To be honest i don't , sorry. so in the last example if i just split them up into two file it will work?

     

    I know what i want.. i want the value from the slider to be put into the variable $ptz.. then i want php to do the math and output the results...

     

    I'm not sure you understand what Ajax is. In this example, data is sent via Javascript back to the server to php, php then does some calculations and sends the data back to Javascript, Javascript then displays the results.

     

    if i put it into a separate file would i need to refresh the page.. i want to achieve this without refreshing the page..

     

    No.

     

    Have you looked at the last example I have posted? Its does what your after.

  3. I know what i want.. i want the value from the slider to be put into the variable $ptz.. then i want php to do the math and output the results... if i put it into a separate file would i need to refresh the page.. i want to achieve this without refreshing the page..

     

    Thanks..

    Sorry but, you might want to start actually thinking about what's going on for yourself. So far you haven't done anything that actually requires php, are you going to save this data to a database or something?

     

    Anyway, you need to have the data echo'd from php back to the javascript.

     

    <?php
    if (isset($_POST['slider'])) {
      $ptz = $_POST['slider'];
    
      /// Grabs user input.
      $prce = 500;
      $points = 2000;
    
      // Sets discount.
      $price = $prce;
      $dis = '0.01';
      $price2 = $price * $dis; // gets discount from price
    
      // sets percentage per x amount of ptz.
      $pts = $ptz;
      $perc1 = '100'; // above 1% = 100 ptz
      $total = $pts / $perc1; // users ptz divided by 100 ptz
      $mtotal = $price2 * $total; // discount multiplied by result above.
    
      // Subtracts discount from price.
      $ftotal = $price - $mtotal;
    
      $arr = array(
        "Points" => $points,
        "Price" => $prce,
        "Discount" => $ftotal
      );
    
      @header("Content-type: application/json");
      echo json_encode($arr);
    
    ?>
    }
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" />
        </head>
        <body>
            <div id="foo">Data returned from php will show here.</div>
            <div id="scrollbar"></div>
        </body>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#scrollbar').slider({
                    value: 0,
                    slide: function(event, ui) {
                        $('#scrollbar').slider('value', ui.value);
                        $.ajax({
                            type: 'post',
                            url: '#',
                            datatype: 'json',
                            data: {'slider': ui.value},
                            success: function(fromphp) {
                                $('#foo').html("Points = " + fromphp.Points + "<br />Price = " + fromphp.Price + "<br />Discount Price = " + fromphp.Discount + "<br />");
                            }
                        });
                    }
                });
            });
        </script>
    </html>
    

     

    Actually study this example and try and figure out whats going on. It would probably be easier to see whats going on if the php was in a separate file.

  4. The reason is that the variable doesn't actually exist until you use the slider.

     

    Just move all your php into the first if statement.

     

    if (isset($_POST['slider'])) {
      $ptz = $_POST['slider'];
      // rest of your code
    }
    

     

    ok i'll give that a try...

     

    EDIT: After doing that the slider shows no output only "Data returned from php will show here."

  5. Here it is... using your first complete example..

     

    <?php
    if (isset($_POST['slider'])) {
      $ptz = $_POST['slider'];
    } else {
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.3/themes/base/jquery-ui.css" type="text/css" />
        </head>
        <body>
            <div id="foo">Data returned from php will show here.</div>
            <div id="scrollbar"></div>
        </body>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                $('#scrollbar').slider({
                    value: 0,
                    slide: function(event, ui) {
                        $('#scrollbar').slider('value', ui.value);
                        $.ajax({
                            type: 'post',
                            url: '#',
                            datatype: 'json',
                            data: {'slider': ui.value},
                            success: function(fromphp) {
                                $('#foo').html(fromphp.data);
                            }
                        });
                    }
                });
            });
        </script>
    </html>
    <?php } ?>
    <?php
    
    /// Grabs user input.
    $prce = 500;
    $points = 2000;
    
    
    // Sets discount.
    $price = $prce;
    $dis = '0.01';
    $price2 = $price * $dis; // gets discount from price
    
    // sets percentage per x amount of ptz.
    $pts = $ptz;
    $perc1 = '100'; // above 1% = 100 ptz
    $total = $pts / $perc1; // users ptz divided by 100 ptz
    $mtotal = $price2 * $total; // discount multiplied by result above.
    
    // Subtracts discount from price.
    $ftotal = $price - $mtotal;
    
    echo "Points = ".$points."<br />";
    echo "Price = ".$prce."<br />";
    echo "Discount Price = ".$ftotal."<br />";
    
    ?>
    

  6. Hey guys i need some help on this.. i'm pretty new to php and really foreign to AJAX ..

     

    Can anyone tell me how i can change a php variable with a ajax slider without refreshing the page (meaning instantly)...

     

    i'll try give you a example if your not getting what i'm saying or need more info...

     

    ok say i have a normal php file with a ajax slider on it...

     

    and the php goes :

     

    $num1 = $_GET['number'];
    $num2 = 3;
    $num3 = 5;
    
    $total = $num1 + $num2 * $num3;
    
    echo "".$num1." + ".$num2." * ".$num3." = ".$total;
    

     

    now how could i set number which will be from the slider...

     

    If you still dnt understand just let me know and i'll try clear it up...

     

    Any help is appreciated.

     

     

×
×
  • 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.