Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript][MySQL][PHP]Wyświetlanie dialgo
Forum PHP.pl > Forum > Przedszkole
avaster12
Witam mam skrypt który wyświetla mi rekordy z tabeli poprzez jego nazwę i dodałem skrypt iquery do wyświetlenia zawartości w oknie dialog tylko problem polega na tym że kod nie wywołuje się na innych niż 1 rekord w tabeli ? skrypt są w liku index.php
  1.  
  2.  
  3. <script src="external/jquery/jquery.js"></script>
  4. <script src="jquery-ui.js"></script>
  5. $("#accordion").accordion();
  6. $("#dialog").dialog({
  7. autoOpen : false,
  8. width : 650,
  9. height : 530,
  10. buttons : [{
  11. text : "Zamknij",
  12. click : function() {
  13. $(this).dialog("close");
  14. }
  15. },]
  16. });
  17.  
  18. // Link to open the dialog
  19. $("#dialog-link").click(function(event) {
  20. $("#dialog").dialog("open");
  21. event.preventDefault();
  22. });
  23.  
  24.  


i kolejny

  1. $lista = $lz -> lista();
  2. echo '
  3. <tr>
  4. <th class="tg-031e">Numer</th>
  5. <th class="tg-031e">Nazwa</th>
  6. <th class="tg-031e">Kto doał</th>
  7. <th class="tg-031e">Link z YouTube</th>
  8. ';
  9. if (!isset($_SESSION['zalogowany'])) {
  10. } else {
  11. echo '
  12. <th class="tg-031e">Stan</th>
  13. <th class="tg-031e">Usuń</th>
  14. </tr>';
  15. };
  16.  
  17. foreach ($lista as $element) {
  18. if ($element['stan'] == 'T') {
  19. $kupione = 'Pobrane';
  20. } else {
  21. $kupione = 'Czeka';
  22. }
  23.  
  24. echo '
  25. <tr>
  26. <td class="tg-031e">' . $element['id'] . '</td>
  27. <td class="tg-031e">' . $element['nazwa'] . '</td>
  28. <td class="tg-031e">' . $element['dodal'] . '</td>
  29. <td class="tg-031e"><a href="#" id="dialog-link" class="">Podgląd</a></td>
  30. ';
  31. if (!isset($_SESSION['zalogowany'])) {
  32.  
  33. } else {
  34. echo '
  35. <td class="tg-031e"><a href="index.php?akcja=zmien&id=' . $element['id'] . '"> ' . $kupione . ' </a></td>
  36. <td class="tg-031e"><a href="index.php?akcja=usun&id=' . $element['id'] . '"> Usuń </a></td>
  37. </tr>';
  38. };
  39.  
  40. }
  41. echo '</table></div> <div id="dialog" title="Dialog Title">
  42. <iframe width="560" height="315" src="//www.youtube.com/embed/'. $element['yt'] .'?rel=0" frameborder="0" allowfullscreen></iframe>
  43. </div>';
  44. ?>


Odśwież
nospor
Cytat
problem polega na tym że kod nie wywołuje się na innych niż 1 rekord w tabeli ?
No nic dziwnego, jak ty kazdemu elementowi w petli nadajesz to samo ID... ID jak sama nazwa wskazuje ma byc UNIKALNE dla każdego elementu. Jak chcesz hurtowo się dobierać do elementow to masz to robic przez KLASY a nie ID
Turson
W pętli wyświetlasz td z id dialog-link a id MUSI być unikalne, jedno w całym dokumencie. Po prostu zmień na klasę,
avaster12
cały kod php bo nie wiem gdzie dokładnie
  1. <?php
  2. include 'wyloguj.php';
  3. ?>
  4. <html>
  5. <head>
  6. <title>Tu wpisz tytuł strony</title>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8. <link rel="Stylesheet" type="text/css" href="style7.css" />
  9. <link href="jquery-ui.css" rel="stylesheet">
  10.  
  11. </head>
  12. <body>
  13. <div id="nav">
  14. <?php
  15. if (!isset($_SESSION['zalogowany'])) {
  16. echo '
  17. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="logowanie.php">Zaloguj</a></div>';
  18. } else {
  19. echo '
  20. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="index.php?akcja=wyloguj">wyloguj</a></div>
  21. ';
  22. }
  23. ?>
  24.  
  25. <h1>Lista Piosenek</h1>
  26. </div>
  27. <div id="dziecko1">
  28. <form action="index.php?akcja=dodaj" method="post">
  29. Nazwa:
  30. <br />
  31. <input type="text" name="nazwa"/>
  32. <br />
  33. Kto dodaje:
  34. <br />
  35. <input type="text" name="dodal"/>
  36. <br />
  37. Link z YouTube:
  38. <br />
  39. <input type="text" name="yt"/>
  40. <br />
  41. <input type="submit" value="Dodaj"/>
  42. </form>
  43. </div>
  44.  
  45. <?php
  46. require_once ('engine.php');
  47. $lz = new listaPiosenek('root', '', 'piosenik', 'localhost');
  48.  
  49. echo '<div id="dziecko2">
  50. <table class="tg">';
  51.  
  52. if (isset($_GET['akcja'])) {
  53. switch($_GET['akcja']) {
  54. case 'dodaj' :
  55. $lz -> dodaj($_POST['nazwa'], $_POST['dodal'], $_POST['yt']);
  56. break;
  57. case 'usun' :
  58. $lz -> usun($_GET['id']);
  59. break;
  60. case 'zmien' :
  61. $lz -> zmienStan($_GET['id']);
  62. break;
  63. case 'wyloguj' :
  64. wyloguj();
  65. break;
  66. }
  67. }
  68.  
  69. $lista = $lz -> lista();
  70. echo '
  71. <tr>
  72. <th class="tg-031e">Numer</th>
  73. <th class="tg-031e">Nazwa</th>
  74. <th class="tg-031e">Kto doał</th>
  75. <th class="tg-031e">Link z YouTube</th>
  76. ';
  77. if (!isset($_SESSION['zalogowany'])) {
  78. } else {
  79. echo '
  80. <th class="tg-031e">Stan</th>
  81. <th class="tg-031e">Usuń</th>
  82. </tr>';
  83. };
  84.  
  85. foreach ($lista as $element) {
  86. if ($element['stan'] == 'T') {
  87. $kupione = 'Pobrane';
  88. } else {
  89. $kupione = 'Czeka';
  90. }
  91.  
  92. echo '
  93. <tr>
  94. <td class="tg-031e">' . $element['id'] . '</td>
  95. <td class="tg-031e">' . $element['nazwa'] . '</td>
  96. <td class="tg-031e">' . $element['dodal'] . '</td>
  97. <td class="tg-031e"><a href="#" id="dialog-link" class="">Podgląd</a></td>
  98. ';
  99. if (!isset($_SESSION['zalogowany'])) {
  100.  
  101. } else {
  102. echo '
  103. <td class="tg-031e"><a href="index.php?akcja=zmien&id=' . $element['id'] . '"> ' . $kupione . ' </a></td>
  104. <td class="tg-031e"><a href="index.php?akcja=usun&id=' . $element['id'] . '"> Usuń </a></td>
  105. </tr>';
  106. };
  107.  
  108. }
  109. echo '</table></div> <div id="dialog" title="Dialog Title">
  110. <iframe width="560" height="315" src="//www.youtube.com/embed/'. $element['yt'] .'?rel=0" frameborder="0" allowfullscreen></iframe>
  111. </div>';
  112. ?>
  113.  
  114. </body>
  115. </html>
  116. <script src="external/jquery/jquery.js"></script>
  117. <script src="jquery-ui.js"></script>
  118. <script>
  119. $("#accordion").accordion();
  120. $("#dialog").dialog({
  121. autoOpen : false,
  122. width : 650,
  123. height : 530,
  124. buttons : [{
  125. text : "Zamknij",
  126. click : function() {
  127. $(this).dialog("close");
  128. }
  129. },]
  130. });
  131.  
  132. // Link to open the dialog
  133. $("#dialog-link").click(function(event) {
  134. $("#dialog").dialog("open");
  135. event.preventDefault();
  136. });
  137. </script>
  138.  
Turson
Linia 98
avaster12
no to nie pomogło
Turson
Pokaz jak zmieniles
nospor
facepalmxd.gif
Co nie pomogło?? SKad mamy wiedziec co "poprawiles"...
avaster12
  1.  
  2. <?php
  3. include 'wyloguj.php';
  4. ?>
  5. <html>
  6. <head>
  7. <title>Tu wpisz tytuł strony</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <link rel="Stylesheet" type="text/css" href="style7.css" />
  10. <link href="jquery-ui.css" rel="stylesheet">
  11.  
  12. </head>
  13. <body>
  14. <div id="nav">
  15. <?php
  16. if (!isset($_SESSION['zalogowany'])) {
  17. echo '
  18. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="logowanie.php">Zaloguj</a></div>';
  19. } else {
  20. echo '
  21. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="index.php?akcja=wyloguj">wyloguj</a></div>
  22. ';
  23. }
  24. ?>
  25.  
  26. <h1>Lista Piosenek</h1>
  27. </div>
  28. <div id="dziecko1">
  29. <form action="index.php?akcja=dodaj" method="post">
  30. Nazwa:
  31. <br />
  32. <input type="text" name="nazwa"/>
  33. <br />
  34. Kto dodaje:
  35. <br />
  36. <input type="text" name="dodal"/>
  37. <br />
  38. Link z YouTube:
  39. <br />
  40. <input type="text" name="yt"/>
  41. <br />
  42. <input type="submit" value="Dodaj"/>
  43. </form>
  44. </div>
  45.  
  46. <?php
  47. require_once ('engine.php');
  48. $lz = new listaPiosenek('root', '', 'piosenik', 'localhost');
  49.  
  50. echo '<div id="dziecko2">
  51. <table class="tg">';
  52.  
  53. if (isset($_GET['akcja'])) {
  54. switch($_GET['akcja']) {
  55. case 'dodaj' :
  56. $lz -> dodaj($_POST['nazwa'], $_POST['dodal'], $_POST['yt']);
  57. break;
  58. case 'usun' :
  59. $lz -> usun($_GET['id']);
  60. break;
  61. case 'zmien' :
  62. $lz -> zmienStan($_GET['id']);
  63. break;
  64. case 'wyloguj' :
  65. wyloguj();
  66. break;
  67. }
  68. }
  69.  
  70. $lista = $lz -> lista();
  71. echo '
  72. <tr>
  73. <th class="tg-031e">Numer</th>
  74. <th class="tg-031e">Nazwa</th>
  75. <th class="tg-031e">Kto doał</th>
  76. <th class="tg-031e">Link z YouTube</th>
  77. ';
  78. if (!isset($_SESSION['zalogowany'])) {
  79. } else {
  80. echo '
  81. <th class="tg-031e">Stan</th>
  82. <th class="tg-031e">Usuń</th>
  83. </tr>';
  84. };
  85.  
  86. foreach ($lista as $element) {
  87. if ($element['stan'] == 'T') {
  88. $kupione = 'Pobrane';
  89. } else {
  90. $kupione = 'Czeka';
  91. }
  92.  
  93. echo '
  94. <tr>
  95. <td class="tg-031e">' . $element['id'] . '</td>
  96. <td class="tg-031e">' . $element['nazwa'] . '</td>
  97. <td class="tg-031e">' . $element['dodal'] . '</td>
  98. <td class="tg-031e"><a href="#" class="dialog-link">Podgląd</a></td>
  99. ';
  100. if (!isset($_SESSION['zalogowany'])) {
  101.  
  102. } else {
  103. echo '
  104. <td class="tg-031e"><a href="index.php?akcja=zmien&id=' . $element['id'] . '"> ' . $kupione . ' </a></td>
  105. <td class="tg-031e"><a href="index.php?akcja=usun&id=' . $element['id'] . '"> Usuń </a></td>
  106. </tr>';
  107. };
  108.  
  109. }
  110. echo '</table></div> <div id="dialog" title="Dialog Title">
  111. <iframe width="560" height="315" src="//www.youtube.com/embed/'. $element['yt'] .'?rel=0" frameborder="0" allowfullscreen></iframe>
  112. </div>';
  113. ?>
  114.  
  115. </body>
  116. </html>
  117. <script src="external/jquery/jquery.js"></script>
  118. <script src="jquery-ui.js"></script>
  119. <script>
  120. $("#accordion").accordion();
  121. $("#dialog").dialog({
  122. autoOpen : false,
  123. width : 650,
  124. height : 530,
  125. buttons : [{
  126. text : "Zamknij",
  127. click : function() {
  128. $(this).dialog("close");
  129. }
  130. },]
  131. });
  132.  
  133. // Link to open the dialog
  134. $("#dialog-link").click(function(event) {
  135. $("#dialog").dialog("open");
  136. event.preventDefault();
  137. });
  138. </script>
  139.  
nospor
No ale tu:
$("#dialog-link")
nadal sie odwolujesz do IDkow.... przeciez zamieniles IDki na klasy to i odwolywac masz sie do klasy. Nie sadzisz ze to dosc logiczne?
avaster12
tylko że wyświetla mi 1 rekord w obu przyciskach
  1.  
  2. <?php
  3. include 'wyloguj.php';
  4. ?>
  5. <html>
  6. <head>
  7. <title>Tu wpisz tytuł strony</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <link rel="Stylesheet" type="text/css" href="style7.css" />
  10. <link href="jquery-ui.css" rel="stylesheet">
  11.  
  12. </head>
  13. <body>
  14. <div id="nav">
  15. <?php
  16. if (!isset($_SESSION['zalogowany'])) {
  17. echo '
  18. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="logowanie.php">Zaloguj</a></div>';
  19. } else {
  20. echo '
  21. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="index.php?akcja=wyloguj">wyloguj</a></div>
  22. ';
  23. }
  24. ?>
  25.  
  26. <h1>Lista Piosenek</h1>
  27. </div>
  28. <div id="dziecko1">
  29. <form action="index.php?akcja=dodaj" method="post">
  30. Nazwa:
  31. <br />
  32. <input type="text" name="nazwa"/>
  33. <br />
  34. Kto dodaje:
  35. <br />
  36. <input type="text" name="dodal"/>
  37. <br />
  38. Link z YouTube:
  39. <br />
  40. <input type="text" name="yt"/>
  41. <br />
  42. <input type="submit" value="Dodaj"/>
  43. </form>
  44. </div>
  45.  
  46. <?php
  47. require_once ('engine.php');
  48. $lz = new listaPiosenek('root', '', 'piosenik', 'localhost');
  49.  
  50. echo '<div id="dziecko2">
  51. <table class="tg">';
  52.  
  53. if (isset($_GET['akcja'])) {
  54. switch($_GET['akcja']) {
  55. case 'dodaj' :
  56. $lz -> dodaj($_POST['nazwa'], $_POST['dodal'], $_POST['yt']);
  57. break;
  58. case 'usun' :
  59. $lz -> usun($_GET['id']);
  60. break;
  61. case 'zmien' :
  62. $lz -> zmienStan($_GET['id']);
  63. break;
  64. case 'wyloguj' :
  65. wyloguj();
  66. break;
  67. }
  68. }
  69.  
  70. $lista = $lz -> lista();
  71. echo '
  72. <tr>
  73. <th class="tg-031e">Numer</th>
  74. <th class="tg-031e">Nazwa</th>
  75. <th class="tg-031e">Kto doał</th>
  76. <th class="tg-031e">Link z YouTube</th>';
  77. if (!isset($_SESSION['zalogowany'])) {
  78. } else {
  79. echo '
  80. <th class="tg-031e">Stan</th>
  81. <th class="tg-031e">Usuń</th>
  82. </tr>';
  83. };
  84.  
  85. foreach ($lista as $element) {
  86. if ($element['stan'] == 'T') {
  87. $kupione = 'Pobrane';
  88. } else {
  89. $kupione = 'Czeka';
  90. }
  91.  
  92. echo ' <tr>
  93. <td class="tg-031e">' . $element['id'] . '</td>
  94. <td class="tg-031e">' . $element['nazwa'] . '</td>
  95. <td class="tg-031e">' . $element['dodal'] . '</td>
  96. <td class="tg-031e"><a href="#" class="dialog-link">Podgląd</a></td>';
  97. if (!isset($_SESSION['zalogowany'])) {
  98. } else {
  99. echo '<td class="tg-031e"><a href="index.php?akcja=zmien&id=' . $element['id'] . '"> ' . $kupione . ' </a></td>
  100. <td class="tg-031e"><a href="index.php?akcja=usun&id=' . $element['id'] . '"> Usuń </a></td>
  101. </tr>';
  102. };
  103. }
  104. echo '</table></div><div id="dialog" title="Dialog Title"><iframe width="560" height="315" src="//www.youtube.com/embed/' . $element['yt'] . '?rel=0" frameborder="0" allowfullscreen></iframe></div>';
  105. ?>
  106. </body>
  107. </html>
  108. <script src="external/jquery/jquery.js"></script>
  109. <script src="jquery-ui.js"></script>
  110. <script>
  111. $("#accordion").accordion();
  112. $("#dialog").dialog({
  113. autoOpen : false,
  114. width : 650,
  115. height : 530,
  116. buttons : [{
  117. text : "Zamknij",
  118. click : function() {
  119. $(this).dialog("close");
  120. }
  121. },]
  122. });
  123.  
  124. // Link to open the dialog
  125. $(".dialog-link").click(function(event) {
  126. $("#dialog").dialog("open");
  127. event.preventDefault();
  128. });
  129. </script>
  130.  
nospor
No chlopie, przyszedles z problemem, ze otwiera ci dialog tylko dla pierwszego elementu a dla innych w ogole nie reaguje. Ten problem juz zdaje się rozwiązalismy. Otwiera ci dialog dla każdego przycisku.

A to ze otwiera ci ciagle ten sam dialog, to juz inny problem.
Tworzysz tylko jeden dialog do otwarcia o tej samej tresci, wiec trudno sie dziwic, że tylko jego ci otwiera. Chcesz by otwierał dla kazdego przycisku co innego, to
albo tworz tyle dialogow ile przyciskow kazdy z czym innym
albo tworz jeden dialog, ale dynamicznie zmieniaj mu tresc
avaster12
no dobra tylko jak to zrobić aby ten div zmieniał zawartość

  1.  
  2. <?php
  3. include 'wyloguj.php';
  4. ?>
  5. <html>
  6. <head>
  7. <title>Tu wpisz tytuł strony</title>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <link rel="Stylesheet" type="text/css" href="style7.css" />
  10. <link href="jquery-ui.css" rel="stylesheet">
  11. <script src="external/jquery/jquery.js"></script>
  12. <script src="jquery-ui.js"></script>
  13.  
  14. </head>
  15. <body>
  16. <div id="nav">
  17. <?php
  18. if (!isset($_SESSION['zalogowany'])) {
  19. echo '
  20. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="logowanie.php">Zaloguj</a></div>';
  21. } else {
  22. echo '
  23. <div id="Zaloguj"><a title="Tylko dla Administratora!" href="index.php?akcja=wyloguj">wyloguj</a></div>
  24. ';
  25. }
  26. ?>
  27.  
  28. <h1>Lista Piosenek</h1>
  29. </div>
  30. <div id="dziecko1">
  31. <form action="index.php?akcja=dodaj" method="post">
  32. Nazwa:
  33. <br />
  34. <input type="text" name="nazwa"/>
  35. <br />
  36. Kto dodaje:
  37. <br />
  38. <input type="text" name="dodal"/>
  39. <br />
  40. Link z YouTube:
  41. <br />
  42. <input type="text" name="yt"/>
  43. <br />
  44. <input type="submit" value="Dodaj"/>
  45. </form>
  46. </div>
  47.  
  48. <?php
  49. require_once ('engine.php');
  50. $lz = new listaPiosenek('root', '', 'piosenik', 'localhost');
  51.  
  52. echo '<div id="dziecko2">
  53. <table class="tg">';
  54.  
  55. if (isset($_GET['akcja'])) {
  56. switch($_GET['akcja']) {
  57. case 'dodaj' :
  58. $lz -> dodaj($_POST['nazwa'], $_POST['dodal'], $_POST['yt']);
  59. break;
  60. case 'usun' :
  61. $lz -> usun($_GET['id']);
  62. break;
  63. case 'zmien' :
  64. $lz -> zmienStan($_GET['id']);
  65. break;
  66. case 'wyloguj' :
  67. wyloguj();
  68. break;
  69. }
  70. }
  71.  
  72. $lista = $lz -> lista();
  73. echo '
  74. <tr>
  75. <th class="tg-031e">Numer</th>
  76. <th class="tg-031e">Nazwa</th>
  77. <th class="tg-031e">Kto doał</th>
  78. <th class="tg-031e">Link z YouTube</th>';
  79. if (!isset($_SESSION['zalogowany'])) {
  80. } else {
  81. echo '
  82. <th class="tg-031e">Stan</th>
  83. <th class="tg-031e">Usuń</th>
  84. </tr>';
  85. };
  86.  
  87. foreach ($lista as $element) {
  88. if ($element['stan'] == 'T') {
  89. $kupione = 'Pobrane';
  90. } else {
  91. $kupione = 'Czeka';
  92. }
  93.  
  94. echo ' <tr>
  95. <td class="tg-031e">' . $element['id'] . '</td>
  96. <td class="tg-031e">' . $element['nazwa'] . '</td>
  97. <td class="tg-031e">' . $element['dodal'] . '</td>
  98. <td class="tg-031e"><a href="#" class="dialog-link">Podgląd</a></td>';
  99. if (!isset($_SESSION['zalogowany'])) {
  100. } else {
  101. echo '<td class="tg-031e"><a href="index.php?akcja=zmien&id=' . $element['id'] . '"> ' . $kupione . ' </a></td>
  102. <td class="tg-031e"><a href="index.php?akcja=usun&id=' . $element['id'] . '"> Usuń </a></td>
  103. </tr>';
  104. };
  105. }
  106. echo '
  107. <div id="dialog" title="Podglond"><center><iframe width="560" height="315" src="//www.youtube.com/embed/' . $element['yt'] . '?rel=0" frameborder="0" allowfullscreen></iframe></center></div>
  108. </table></div>';
  109. ?>
  110. </body>
  111. </html>
  112.  
  113. <script>
  114. $("#accordion").accordion();
  115. $("#dialog").dialog({
  116. autoOpen : false,
  117. width : 650,
  118. height : 530,
  119. buttons : [{
  120. text : "Zamknij",
  121. click : function() {
  122. $(this).dialog("close");
  123. }
  124. },]
  125. });
  126.  
  127. // Link to open the dialog
  128. $(".dialog-link").click(function(event) {
  129. $("#dialog").dialog("open");
  130. event.preventDefault();
  131. });
  132. </script>
  133.  
Turson
A skąd ma wziąc wartość?
$('#dialog').html('jakaś wartość');
avaster12
108 linia
Turson
title="Podglond" facepalmxd.gif
Po prostu stwórz dla każdego elementu tablicy osobny dialog i ładuj odpowiedni po kliknięciu.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.