Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>asd</title>
  5.     <?php
  6.     $servername = "localhost";
  7.     $username = "root";
  8.     $password = "jp2gmd";
  9.     $dbname = "muzyka";
  10.  
  11.     $connection = new mysqli($servername, $username, $password, $dbname);
  12.     if ($connection->connect_error)
  13.         die("Connection failed: ".$connection->connect_error);
  14.  
  15.     $sql[0] = "SELECT nazwa from artysci";
  16.     $result = $connection->query($sql[0]);
  17.     echo(
  18.      "<script>".
  19.      "var wykonawcy = [");
  20.     foreach ($result as $key => $value) {
  21.       echo("\"".$value["nazwa"]."\",");
  22.   }
  23.   echo("];".
  24.      "</script>"
  25.      );
  26.  
  27.   $ilosc = "SELECT count(nazwa) FROM artysci";
  28.   for($i=0; $i<$ilosc; $i++){
  29.     $sql[$i] = "SELECT tytul from albumy where id_artysty='$i+1'";
  30.     $result[$i] = $connection->query($sql[$i]);
  31.     echo(
  32.         "<script>".
  33.         "var albumy[$i] = [");
  34.     foreach ($result[$i] as $key => $value) {
  35.         echo("\"".$value["tytul"]."\",");
  36.     }
  37.     echo("];".
  38.         "</script>"
  39.         );
  40. }
  41.  
  42.         ?>
  43.         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  44.         <script type="text/javascript">
  45.             $(document).ready(function(){
  46.                 var $el = $("#selectId");
  47.             $el.empty();
  48.             for (var i=0; i<wykonawcy.length; i++)
  49.                 $el.append($("<option></option>").attr("value", i).text(wykonawcy[i]));
  50.         });
  51.             function selected(albumy, value){
  52.                 alert(albumy[value]);
  53.             }
  54.         </script>
  55.     </head>
  56.     <body>
  57.         <form>
  58.             <select id="selectId" onchange="selected(this.value)">
  59.                 <option>asd</option>
  60.             </select>
  61.         </form>
  62.     </body>
  63.     </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement