Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>asd</title>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "jp2gmd";
- $dbname = "muzyka";
- $connection = new mysqli($servername, $username, $password, $dbname);
- if ($connection->connect_error)
- die("Connection failed: ".$connection->connect_error);
- $sql[0] = "SELECT nazwa from artysci";
- $result = $connection->query($sql[0]);
- echo(
- "<script>".
- "var wykonawcy = [");
- foreach ($result as $key => $value) {
- echo("\"".$value["nazwa"]."\",");
- }
- echo("];".
- "</script>"
- );
- $ilosc = "SELECT count(nazwa) FROM artysci";
- for($i=0; $i<$ilosc; $i++){
- $sql[$i] = "SELECT tytul from albumy where id_artysty='$i+1'";
- $result[$i] = $connection->query($sql[$i]);
- echo(
- "<script>".
- "var albumy[$i] = [");
- foreach ($result[$i] as $key => $value) {
- echo("\"".$value["tytul"]."\",");
- }
- echo("];".
- "</script>"
- );
- }
- ?>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- var $el = $("#selectId");
- $el.empty();
- for (var i=0; i<wykonawcy.length; i++)
- $el.append($("<option></option>").attr("value", i).text(wykonawcy[i]));
- });
- function selected(albumy, value){
- alert(albumy[value]);
- }
- </script>
- </head>
- <body>
- <form>
- <select id="selectId" onchange="selected(this.value)">
- <option>asd</option>
- </select>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement