Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!