Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Dynamic Switch from Database Logic Question

While looking through stackoverflow I found the following: How to create a dynamic PHP switch statement from MySQL query

Which resulted in me trying something I haven't before, it doesn't work, but I am curious as to why it doesn't work rather than trying to figure out a way to make it work.

Here's my code:

function SOMENAME(){
global $mysqli ;
$out = false ;
$VALIDTOKENS = array();
$sql = "SELECT * FROM `tokens` ORDER BY `tokens`.`id` ASC";
            if($result = mysqli_query($mysqli, $sql)) {
                while ($row = mysqli_fetch_assoc($result)) {
                    $VALIDTOKENS[$row['token']] = $row['token'];
                    }
            }
    if(isset($_GET['key'])) {
    $key = $_GET['key'];    
    }

    switch($key) {
            case $VALIDTOKENS[$key]:
                $out = true ;
            break;
    } 
return $out ;
}

The function always returns false.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

From the logic of your code,when it returns false, there are many possibilities, such as the database failed to link, the query failed, the database table does not exist, the field does not exist, etc. You are advised to debug with breakpoints, you can use var_dump() in different lines of code, check the returned results.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda