0

I want to call the PHP variable "rate number" as "phpvalue" in jQuery. But the alert of "phpvalue" does not give any output and the alert of "num3" gives "NaN" as the output.

Here is my PHP code.

$jsqla = mysql_query("select id,name,rate_score,rate_number,video_image from products where genre='$genre' limit 0,5");

while($jrowa = mysql_fetch_assoc($jsqla)){
    $arate_num = $jrowa['rate_number'];
}

Here is my jQuery code.

$(function(){
    $(document).ready(function(e) {
        var $stars = $('.input-star-rate');

        $stars.bind('change', function() {

            var phpvalue = "<?php echo $jrowa['rate_score']; ?>";
            alert(phpvalue);

            var num3 = parseInt(phpvalue, 10);
            alert(num3);

        });
    });
});

Here is my HTML code.

<input class="rating form-control input-star-rate" id="<?php echo $rateid; ?>" name="rating" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>
2
  • Is the jQuery code also processed by PHP? Commented Nov 28, 2014 at 6:28
  • possible duplicate of Use a PHP variable in JQuery Commented Nov 28, 2014 at 6:28

1 Answer 1

3

try

  $(function(){
    $(document).ready(function(e) {
        var $stars = $('.input-star-rate');

        $stars.bind('change', function() {

            var phpvalue = "<?php echo $arate_num; ?>";
            alert(phpvalue);

            var num3 = parseInt(phpvalue, 10);
            alert(num3);

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

Comments

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.