php - trying to simplify the update code -


i want update following words in identifier_flag field, there simpler way currenty have?

$temp_query = "select * faq";  $sql = mysqli_query($connection, $temp_query); while($row = mysqli_fetch_assoc($sql)){     if(preg_match("/price/", $row['question'])){         $update = "update faq set identifier_flag = 'price' id = '".$row['id']."'";         mysqli_query($connection, $update);     }     if(preg_match("/colours/", $row['question'])){         $update = "update faq set identifier_flag = 'colours' id = '".$row['id']."'";         mysqli_query($connection, $update);     }     if(preg_match("/versions/", $row['question'])){         $update = "update faq set identifier_flag = 'versions' id = '".$row['id']."'";         mysqli_query($connection, $update);     }     if(preg_match("/oil/", $row['question'])){         $update = "update faq set identifier_flag = 'oil' id = '".$row['id']."'";         mysqli_query($connection, $update);     }     if(preg_match("/seating/", $row['question'])){         $update = "update faq set identifier_flag = 'seating' id = '".$row['id']."'";         mysqli_query($connection, $update);     }      if(preg_match("/warranty/", $row['question'])){         $update = "update faq set identifier_flag = 'warranty' id = '".$row['id']."'";         mysqli_query($connection, $update);     } } 

so many ways this. brain see this

$temp_query = "select * faq";  $flags = ['flag1','flag2']; $sql = mysqli_query($connection,$temp_query); while($row = mysqli_fetch_assoc($sql)){      foreach($flags $k=>$v) {         if(preg_match('/'.$v.'/',$row['question'])) {             $update = "update faq set identifier_flag = '{$v}' id = '".$row['id']."'";             mysqli_query($connection,$update);             //continue; //to go next result         }     } } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -