Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda