Return more than one variable in Jquery/PHP

Asked

Viewed 50 times

1

Being objective, my problem is this:

I have a form in PHP/HTML and I am using a self-paced field via Jquery. This form brings the last numbers wagered by the user and redoes the bet with this numbers automatically without it having to type all over again.

So I have two files:

1) Form where the user selects the draw that he wishes to repeat the bet;

2) Page in . php that receives the request of the form according to the draw chosen by the user, filters and returns the numbers of that draw chosen for the form.

In the case of the 02 file, when pulling with the file alone, that is, opening it in the browser it returns me the correct value of the numbers of that user corresponding to the chosen draw, but when trying to select the draw in the 01 file it does not pull and fill the data... There lies my doubt, what may be going wrong?

Let’s go to the codes:

File 01:

        <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript">
        function numeroConcurso(id){
                $.post("paginas/repetiraposta.php",{idConcurso:id},function(retorno){
                    dados = retorno.split("/");
                    $('#num01').val(dados[0]);
                    $('#num02').val(dados[1]);
                    $('#num03').val(dados[2]);
                    $('#num04').val(dados[3]);
                    $('#num05').val(dados[4]);
                    $('#num06').val(dados[5]);
                    $('#num07').val(dados[6]);
                    $('#num08').val(dados[7]);
                    $('#num09').val(dados[8]);
                    $('#num10').val(dados[9]);
                    $('#num11').val(dados[10]);
                    $('#num12').val(dados[11]);
                    $('#num13').val(dados[12]);
                    $('#num14').val(dados[13]);
                    $('#num15').val(dados[14]);
                    });
            }
    </script>

<!--FORMULÁRIO-->

<label>Repetir aposta do concurso:[EM DESENVOLVIMENTO]</label>
    <select name="concurso" onchange="numeroConcurso(this.value)">
        <option value="">Escolha um concurso</option>
            <?php 
                $sql2 = mysql_query("SELECT * FROM numeros WHERE usuario='$usuario'");
                while($sorteio_atual = mysql_fetch_object($sql2)){
                echo "
                <option value='$sorteio_atual->sorteio'>
                        $sorteio_atual->sorteio</option>
                ";
                }
            ?>
    </select>

Archive 02:

$usuario1 = $_SESSION['usuario'];
$id = $_POST['idConcurso'];
$sqlConcurso = mysql_query("SELECT * FROM numeros WHERE usuario='$usuario1'");
$concurso = mysql_fetch_object($sqlConcurso);
$dados = $concurso->numero01."/".$concurso->numero02."/".$concurso->numero03."/".$concurso->numero04."/".$concurso->numero05."/".$concurso->numero06."/".$concurso->numero07."/".$concurso->numero08."/".$concurso->numero09."/".$concurso->numero10."/".$concurso->numero11."/".$concurso->numero12."/".$concurso->numero13."/".$concurso->numero14."/".$concurso->numero15."/".$concurso->usuario;
    echo $dados;

So that’s it:

I want the guy when selecting the draw, the numbers corresponding to the code to return in the form automatically for him to redo his bet!

Obs.: If I change the 02 file to:

$sqlConcurso = mysql_query("SELECT * FROM numeros WHERE usuario='$usuario1'");

Form 01 returns the numbers of all players without filtering by user name.

Filter control is being carried out in function: $_SESSION['usuario']

If necessary, the code example is on the website:

loteriamxt.Tk

Guide "Betting!".

I thank you all for your attention!

This was the code inside the 02 file:

session_start(); 

$usuario1 = $_SESSION['usuario']; 

$id = $_POST['idConcurso']; $sqlConcurso = mysql_query("SELECT * FROM numeros WHERE sorteio='$id' AND usuario='$usuario1'"); 

Filtering by user and by draw number selected in the form! Many Thanks Anderson Carlos Woss!

  • Before dados = retorno.split("/");, check via console.log what’s coming for Javascript.

  • How do I verify that?

  • console.log(retorno), check the output in the browser console.

  • /////////////// Only the bars that divide the numbers came out. ....

  • If I change the $sqlConcourse = mysql_query("SELECT * FROM numbers WHERE usuario='$usuario1'"); according to the request of the file 01(idConcourse:id), getting :$sqlConcourse = mysql_query("SELECT * FROM numbers WHERE draw='$id'"); The console returns me: 07/13/15/23/25/33/45/12/08/17/35/37///francis1505 ...

  • You are calling the function session_start?

  • Not directly in the file, but in query inside the file with echo $usuario1; where $usuario1 = $_SESSION['user'];, it returns to me the name of my user, or the user who is logged in to the system.

  • Dude was the Session!!! This is the code inside the 02: session_start(); $usuario1 = $_SESSION['user']; $id = $_POST['idConcurso']; $sqlConcurso = mysql_query("SELECT * from numbers where draw='$id' AND user='$usuario1'"); Filtering by user and by draw number selected in the form! Thank you very much!

Show 3 more comments

1 answer

-1

This was the code inside the 02 file:

session_start(); 

$usuario1 = $_SESSION['usuario']; 

$id = $_POST['idConcurso']; $sqlConcurso = mysql_query("SELECT * FROM numeros WHERE sorteio='$id' AND usuario='$usuario1'");

Filtering by user and by draw number selected in the form! Many Thanks Anderson Carlos Woss!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.