Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

php - Pass time/date time URL for API [WORDPRESS]

I would need to pass to URL a date in order to extract all the records from my table since that date. Problem is, I don't know the correct way to pass a date via URL.

In place of "HEREHERE" what should I put to pass a date?

register_rest_route('cp/v1', '/logcaptiveportal/data/HEREHERE', [
    'methods' => 'GET',
    'callback' => 'get_data_log',
    'permission_callback' => function($request){
        return is_user_logged_in();},
]);

And what does it use to extract it?

function get_data_log($data){
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysqli_select_db($conn, DB_NAME);
global $wpdb;
$pr = $wpdb->prefix;
$response = array();
$datalog = $data['id'];
/*Estraggo durata di navigazione*/
$getusermeta = "SELECT * FROM " . $pr . "logcaptiveportal WHERE Orario LIKE '%$datalog%'";
$result = $conn->query($getusermeta);
if ($result->num_rows > 0) 
{
    // output data of each row
    while($row = $result->fetch_assoc()) 
    {
        $response[$i]['User ID'] = $row["user_id"];
        $response[$i]['Nickname'] = $row["nickname"];
        $response[$i]['Pagina visitata'] = $row["pagina_visitata"];
        $response[$i]['Mac-Address'] = $row["user_mac"];
        $response[$i]['Orario'] = $row["Orario"];
        $response[$i]['link'] = $_SERVER['REQUEST_URI'];
        $i++;
    }
    echo json_encode($response,JSON_PRETTY_PRINT);
}
else 
    echo "Non esiste nessun log con il/la seguente orario/data: ".$datalog."";

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...