How to loop within a query?

Asked

Viewed 314 times

1

I have a list of phone numbers and their operators. This list is presented in icon format and when the mouse on top appears the number related to the operator in the format of tooltip. But the same number is appearing for all operators as can be seen here, just hover over the phone icon in the lower right corner.

My query is like this:

$tel_query = "SELECT * FROM tels";
$variavel_exe = mysql_query($tel_query) or die(mysql_error());
while($variavel = mysql_fetch_array($variavel_exe)){
    $indTelefone=0;
    $indCelular=0;
    while($tipo = mysql_fetch_array($variavel_exe)){
        if($tipo['tipo']=='fixo'){
            $arrayTelefone[$indTelefone]['numero'] = $tipo['numero'];
            $indTelefone++;
        }else{
            $arrayCelular[$indCelular]['numero'] = $tipo['numero'];
            $indCelular++;
        }
    }
}

Can a colleague please help me sort this thing out? Thank you!

In time, I’m using Google Material Design for the interface (the framework is fantastic) and of course, PHP with Mysql.

  • I realized there’s two loops, one inside the other, what exactly are you trying to do? The code is very messy, can explain how this the table structure and an example in text even how you want it to look?

1 answer

2

If removing one of the ties will achieve the expected result:

$tel_query = "SELECT * FROM tels";
$variavel_exe = mysql_query($tel_query) or die(mysql_error());

$indTelefone=0;
$indCelular=0;
    while($tipo = mysql_fetch_array($variavel_exe)){
        if($tipo['tipo']=='fixo'){
            $arrayTelefone[$indTelefone]['numero'] = $tipo['numero'];
            $indTelefone++;
        }else{
            $arrayCelular[$indCelular]['numero'] = $tipo['numero'];
            $indCelular++;
        }
    }
}
  • Oops, thank you! I’ll test it and see how it looks.

Browser other questions tagged

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