Created
April 14, 2022 21:41
-
-
Save atwellpub/37a952f0cbe9c8a07e4db6417883c48b to your computer and use it in GitHub Desktop.
Draft method of retrieving logs from database
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 | |
/* | |
* | |
*/ | |
public function get_special_logs( $query ) { | |
if (!isset($query['special_id']) || !$query['special_id']) { | |
return []; | |
} | |
global $wpdb; | |
$count = 0; | |
$table_name = $wpdb->prefix . "special_logs"; | |
$query = 'SELECT * FROM '.$table_name; | |
if (isset($query['special_id']) && $query['special_id'] && ++$count) { | |
$query .= (!$count ? ' WHERE ' : ' AND ' ) . ' special_id = "'.$query['special_id'].'" '; | |
} | |
if (isset($query['begin_date']) && $query['begin_date'] && ++$count) { | |
$query .= (!$count ? ' WHERE ' : ' AND ' ) . ' datetime >= "'.$query['begin_date'].'" '; | |
} | |
if (isset($query['end_date']) && $query['end_date'] && ++$count) { | |
$query .= (!$count ? ' WHERE ' : ' AND ' ) .' datetime <= "'.$query['end_date'].'" '; | |
} | |
return $wpdb->get_results( $query , ARRAY_A ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment