Created
June 2, 2017 12:11
-
-
Save calexandrepcjr/c7e7ea134e1a7c93689ed4463e3920d8 to your computer and use it in GitHub Desktop.
A helper to play with SQL queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Good to use in PHP pure reports, can send some GET params and automatically filter query with them | |
function addWhere() | |
{ | |
if (isset($_REQUEST) && count($_REQUEST) > 0){ | |
$where = ' WHERE '; | |
foreach ($_REQUEST as $column => $value) { | |
if (is_numeric($value)){ | |
$where .= " $column = $value "; | |
} else { | |
$where .= " $column = '{$value}' "; | |
} | |
} | |
} else { | |
$where = ''; | |
} | |
return $where; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment