Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.21 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8MB4">
  5. </head>
  6. <?php
  7.  
  8. $host = "localhost";
  9. $user = "";
  10. $pass = "";
  11. $dbname = "worldmapping";
  12. $charset = "UTF8MB4";
  13. //$charset = "UTF8";
  14.  
  15. $articleIDs = "";
  16.  
  17.  
  18. $dsn = "mysql:host={$host};dbname={$dbname};charset={$charset}";
  19.  
  20. $options = [
  21.     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // highly recommended
  22.     PDO::ATTR_EMULATE_PREPARES => false // ALWAYS! ALWAYS! ALWAYS!
  23. ];
  24.  
  25. try {
  26.     $dbh = new PDO( $dsn, $user, $pass, $options );
  27.     $dbh->exec("set names utf8");
  28.     $dbh->exec("set character set utf8");
  29.     $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
  30. } catch ( PDOException $e ) {
  31.     // always catch PDOExceptions.
  32.     // If there's a problem here, the error message will probably contain your DB password.
  33.  
  34.     // log the error.
  35.     // during development, if your server is not public, you can display the message instead if you prefer.
  36.     error_log( $e->getMessage() );
  37. }
  38.  
  39.  
  40. if($_GET["location"]!=NULL){
  41.     $selectSQL = "SELECT articles FROM `locations` WHERE location = :location";
  42.     $selectStmt = $dbh->prepare($selectSQL);
  43.     $input = ['location' => $_GET["location"]];
  44.     $selectStmt->execute($input);
  45.     $result = $selectStmt->fetch();
  46.  
  47.     if($result){
  48.         $articleIds=$result['articles'];
  49.         echoArticlesEditedAfter($articleIds, urldecode($_GET["time"]));
  50.     } else {
  51.         echo "no results from query<br>";
  52.     }
  53. //
  54. //    $result = $conn->query($sql);
  55. //
  56. //    if ($result->num_rows > 0) {
  57. //        // output data of each row
  58. //        while($row = $result->fetch_assoc()) {
  59. ////            echo "_id: " . $row["_id"]. "\tlocation: " . $row["location"]. "\tarticles: " . $row["articles"]. "<br>";
  60. //            $articleIDs = $row["articles"];
  61. //            echoArticlesEditedAfter($articleIDs, urldecode($_GET["time"]));
  62. //        }
  63. //    } else {
  64. //        echo "0 results<br>";
  65. //    }
  66. }
  67.  
  68. $dbh=NULL;
  69.  
  70. function echoArticlesEditedAfter($articleIDs, $time){
  71.     global $dbh;
  72.     $input = NULL;
  73.     if(!is_null($articleIDs)){
  74.         if(intval($articleIDs)==0){
  75.             if(!empty($time)){
  76.                 $selectSQL = "SELECT * FROM `articles` WHERE last_edit > :time";
  77.                 $selectStmt = $dbh->prepare($selectSQL);
  78.                 $input = ['time' => $_GET["time"]];
  79.             } else {
  80.                 $selectSQL = "SELECT * FROM `articles`";
  81.                 $selectStmt = $dbh->prepare($selectSQL);
  82.             }
  83.         } else {
  84.             if (!empty($time)) {
  85.                 $selectSQL = "SELECT * FROM `articles` WHERE (_id IN (" . $articleIDs . ")) AND last_edit > :time";
  86.                 $selectStmt = $dbh->prepare($selectSQL);
  87.                 $input = ['time' => $_GET["time"]];
  88.             } else {
  89.                 $selectSQL = "SELECT * FROM `articles` WHERE _id IN (" . $articleIDs . ")";
  90.                 $selectStmt = $dbh->prepare($selectSQL);
  91.             }
  92.         }
  93.         $selectStmt->execute($input);
  94.         echo "<pre>";
  95.         foreach ($selectStmt as $row) {
  96.             echo json_encode($row, JSON_PRETTY_PRINT) . "<br>";
  97.         };
  98.         echo "</pre>";
  99.     } else {
  100.         echo "no query<br>";
  101.     }
  102. }
  103. ?>
  104. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement