Skip to content

Instantly share code, notes, and snippets.

@calexandrepcjr
Created June 2, 2017 12:11
Show Gist options
  • Save calexandrepcjr/c7e7ea134e1a7c93689ed4463e3920d8 to your computer and use it in GitHub Desktop.
Save calexandrepcjr/c7e7ea134e1a7c93689ed4463e3920d8 to your computer and use it in GitHub Desktop.
A helper to play with SQL queries
<?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