0

I was searching for the answer but I couldn't found one for the specific problem, someone says something about ajax or json but I have no idea how to use this things, so I decided to ask a question.

Actualy I'm saving the values from a skill calculator in mysql using php/mysql and jquery for the calculating.

What I need at moment is take a number from mysql and use it as variable, maybe somthing like this:

ranksalvo[0] == 
    <?php
        mysql_select_db("skill");
        $query = mysql_query("SELECT * FROM skillrank WHERE ID = '71' ");
        $rows = mysql_fetch_array($query);
        $rank1 = $rows['rank1'];
    ?>;

if(ranksalvo[0] == 1){      
    $('.archerrank2').slideDown(1000);
}

As you can see its just a very bad example, but I think it shows exactly what I want also why I couldn't find a good enough answer when I was searching it.

Thank you!

<form action="conexao/conexao.php" method="post">
    <script src="jquery.js"></script> 
    <script type="text/javascript">

        var ranksalvo = [0,0,0,0,0,0];
        var skillsalvo = [0,0,0,0,0,0];

        var ranksalvo[0] =  
        <?php
            mysql_select_db("skill");
            $query = mysql_query("SELECT * FROM skillrank WHERE ID = '71' ");
            $rows = mysql_fetch_array($query);
            $rank1 = $rows['rank1'];
            echo "$rank1";
        ?>;

        if(ranksalvo[0] == 1){

            $('#rank1s').slideDown(1000);
            $('#rank2s').slideDown(1000);
            $('#rank3s').slideDown(1000);
            $('#rank4s').slideDown(1000);
            $('#multishot').slideDown(1000);
            $('#fulldraw').slideDown(1000);
            $('#swiftstep').slideDown(1000);
            $('#kneelingshot').slideDown(1000);         
            $('.archerrank2').slideDown(1000);
        }

    </script>
  • to assign values you use only one equal sign ranksalvo[0] = ........ '==' is to compare... – Leo Javier Aug 27 '15 at 15:32
  • Ops, sorry that double ==, but it was just an example, I haven't tried this code. Its just an example and I can't belive its right. ^^ – Cleber Benedet Aug 27 '15 at 15:35
  • "... exactly what I want ..."!! What is the scenario - initial page build or fetching content for a page that's already served? – Roamer-1888 Aug 27 '15 at 16:01
  • Well, the page is already built, I'm changing it to receive value from mysql. – Cleber Benedet Aug 27 '15 at 16:05
  • In that case, it sounds like you correctly identified the need for AJAX, which means intercommunication of a displayed web page with a sever (typically the same server that served the page). – Roamer-1888 Aug 27 '15 at 16:11
  • I understand, is it possible to take a number from mysql and use it as variable in a jquery code with ajax? – Cleber Benedet Aug 27 '15 at 16:17

1 Answers1

0

would be something like:

var ranksalvo[0] = 
    <?php
        mysql_select_db("skill");
        $query = mysql_query("SELECT * FROM skillrank WHERE ID = '71' ");
        $rows = mysql_fetch_array($query);
        $rank1 = $rows['rank1'];
    ?>;

if(ranksalvo[0] == 1){      
    $('.archerrank2').slideDown(1000);
}
Leo Javier
  • 1,383
  • 12
  • 19