Advertisement
Guest User

Untitled

a guest
May 11th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2.  
  3.     //connection information
  4.   $host = "localhost";
  5.   $user = "videolan_vl";
  6.   $password = "*";
  7.   $database = "videolan_vl";
  8.  
  9.     function sqlnez($value)
  10.     {
  11.         // stripslashes
  12.         if (get_magic_quotes_gpc()) {
  13.             $value = stripslashes($value);
  14.         }
  15.         // if not int
  16.         if (!is_numeric($value)) {
  17.             $value = "'" . mysql_real_escape_string($value) . "'";
  18.         }
  19.         return $value;
  20.     }
  21.   $server = mysql_connect($host, $user, $password);
  22.   $connection = mysql_select_db($database, $server);
  23.     if(isset($_GET['id'])) {
  24.     $query = mysql_query("SELECT * FROM tags WHERE lany_id=".sqlnez($_GET['id'])."");
  25.     $json = "({ tags:[";
  26.   for ($x = 0, $numrows = mysql_num_rows($query); $x < $numrows; $x++) {
  27.     $row = mysql_fetch_assoc($query);
  28.     $json .= "{tag:'" . $row["tag"] . "'}";
  29.       if ($x < mysql_num_rows($query) -1)  
  30.           $json .= ",";  
  31.         else  
  32.           $json .= "]})";
  33.   }
  34. }
  35.  
  36.     else    {
  37. $query = mysql_query("SELECT * FROM tags GROUP BY tag") or die ("HIBA! Nem sikerült az SQL valamiért.");
  38. $json = "({ tags:[";
  39. for ($x = 0, $numrows = mysql_num_rows($query); $x < $numrows; $x++) {
  40.   $row = mysql_fetch_assoc($query);
  41.   $json .= "{tag:'" . $row["tag"] . "',count:'" . $row["count"] . "'}";
  42.   if ($x < mysql_num_rows($query) -1)  
  43.       $json .= ",";  
  44.     else  
  45.       $json .= "]})";
  46. }
  47. }
  48.     $response = $_GET["callback"] . $json;
  49.     echo utf8_encode($response);
  50.     mysql_close($server);
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement