Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8MB4">
- </head>
- <?php
- $host = "localhost";
- $user = "";
- $pass = "";
- $dbname = "worldmapping";
- $charset = "UTF8MB4";
- //$charset = "UTF8";
- $articleIDs = "";
- $dsn = "mysql:host={$host};dbname={$dbname};charset={$charset}";
- $options = [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // highly recommended
- PDO::ATTR_EMULATE_PREPARES => false // ALWAYS! ALWAYS! ALWAYS!
- ];
- try {
- $dbh = new PDO( $dsn, $user, $pass, $options );
- $dbh->exec("set names utf8");
- $dbh->exec("set character set utf8");
- $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
- } catch ( PDOException $e ) {
- // always catch PDOExceptions.
- // If there's a problem here, the error message will probably contain your DB password.
- // log the error.
- // during development, if your server is not public, you can display the message instead if you prefer.
- error_log( $e->getMessage() );
- }
- if($_GET["location"]!=NULL){
- $selectSQL = "SELECT articles FROM `locations` WHERE location = :location";
- $selectStmt = $dbh->prepare($selectSQL);
- $input = ['location' => $_GET["location"]];
- $selectStmt->execute($input);
- $result = $selectStmt->fetch();
- if($result){
- $articleIds=$result['articles'];
- echoArticlesEditedAfter($articleIds, urldecode($_GET["time"]));
- } else {
- echo "no results from query<br>";
- }
- //
- // $result = $conn->query($sql);
- //
- // if ($result->num_rows > 0) {
- // // output data of each row
- // while($row = $result->fetch_assoc()) {
- //// echo "_id: " . $row["_id"]. "\tlocation: " . $row["location"]. "\tarticles: " . $row["articles"]. "<br>";
- // $articleIDs = $row["articles"];
- // echoArticlesEditedAfter($articleIDs, urldecode($_GET["time"]));
- // }
- // } else {
- // echo "0 results<br>";
- // }
- }
- $dbh=NULL;
- function echoArticlesEditedAfter($articleIDs, $time){
- global $dbh;
- $input = NULL;
- if(!is_null($articleIDs)){
- if(intval($articleIDs)==0){
- if(!empty($time)){
- $selectSQL = "SELECT * FROM `articles` WHERE last_edit > :time";
- $selectStmt = $dbh->prepare($selectSQL);
- $input = ['time' => $_GET["time"]];
- } else {
- $selectSQL = "SELECT * FROM `articles`";
- $selectStmt = $dbh->prepare($selectSQL);
- }
- } else {
- if (!empty($time)) {
- $selectSQL = "SELECT * FROM `articles` WHERE (_id IN (" . $articleIDs . ")) AND last_edit > :time";
- $selectStmt = $dbh->prepare($selectSQL);
- $input = ['time' => $_GET["time"]];
- } else {
- $selectSQL = "SELECT * FROM `articles` WHERE _id IN (" . $articleIDs . ")";
- $selectStmt = $dbh->prepare($selectSQL);
- }
- }
- $selectStmt->execute($input);
- echo "<pre>";
- foreach ($selectStmt as $row) {
- echo json_encode($row, JSON_PRETTY_PRINT) . "<br>";
- };
- echo "</pre>";
- } else {
- echo "no query<br>";
- }
- }
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement