Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] Jak połączyć
Forum PHP.pl > Forum > Przedszkole
stern
Witam, chciałem w swojej galerii zrobić losowe wyświetlanie zdjęć. Nie wiem w którym miejscu wkleić php do html żeby działało :/


to są kody:
  1. <title>Galery</title>
  2. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" />
  3. <link rel="stylesheet" type="text/css" href="style2.css" />
  4. </head>
  5.  
  6. <table width="100%" cellpadding="0" cellspacing="0" style="height:100%">
  7. <tr>
  8. <td class="left"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
  9. <td class="middle">
  10. <p style="cursor:crosshair;"><img src="images/logo.gif" alt="" width="700" height="180" class="float" /></p>
  11. <div class="leftcol">
  12. </div>
  13. <div class="rightcol">
  14. <div class="group">
  15. <a target="_blank" href="art/CCI_00000.jpg"><img src="art/CCI_00000.jpg" alt="Girl" width="57" height="78" /></a>
  16. <a target="_blank" href="art/CCI_00001.jpg"><img src="art/CCI_00001.jpg" alt="Girl" width="57" height="78" /></a>
  17. <a target="_blank" href="art/CCI_00002.jpg"><img src="art/CCI_00002.jpg" alt="Girl" width="57" height="78" /></a>
  18. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  19. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  20. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  21. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  22. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  23. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  24. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  25. </div>
  26. </div>
  27. </td>
  28. <td class="right"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
  29. </tr>
  30. </table>
  31. </body>
  32. </html>


  1. <?php
  2. $dir = './images/';
  3. $exts = array( 'gif', 'jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'GIF', 'PNG' );
  4. $imgs = array();
  5. if( $d = opendir( $dir ) )
  6. {
  7. while( $f = readdir( $d ) )
  8. {
  9. $ext = explode( '.', $f );
  10. $ext = array_pop( $ext );
  11. if( in_array( strtolower( $ext ), $exts ) )
  12. {
  13. $imgs[] = $f;
  14. }
  15. }
  16. closedir( $d );
  17. }
  18.  
  19. $img = $imgs[ array_rand( $imgs ) ];
  20. echo '<img src="' . $dir . $img . '"/>';
  21.  
  22.  
  23. ?>


Chodzi mi o to aby losowe zdjęcie pokazywało się po lewej stronie galerii.
Tu jest stronka testowa http://mist-sn.ugu.pl/galery.html
cim
Cytat(stern @ 28.12.2009, 11:47:10 ) *
  1. <div class="leftcol">
  2. <?php
  3. /*
  4. * tutaj
  5. */
  6. ?>
  7. </div>

Swoją drogą radzę zrobić to w całości na DIV zamiast tabelek.

Pozdrawiam
stern
niestety nie działa :/ wyświetla tylko
Kod
'; ?>

Wkleiłem tak:
  1. <p style="cursor:crosshair;"><img src="images/logo.gif" alt="" width="700" height="180" class="float" /></p>
  2. <div class="leftcol">
  3. <?php
  4. $dir = './images/';
  5. $exts = array( 'gif', 'jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'GIF', 'PNG' );
  6. $imgs = array();
  7. if( $d = opendir( $dir ) )
  8. {
  9. while( $f = readdir( $d ) )
  10. {
  11. $ext = explode( '.', $f );
  12. $ext = array_pop( $ext );
  13. if( in_array( strtolower( $ext ), $exts ) )
  14. {
  15. $imgs[] = $f;
  16. }
  17. }
  18. closedir( $d );
  19. }
  20.  
  21. $img = $imgs[ array_rand( $imgs ) ];
  22. echo '<img src="' . $dir . $img . '"/>';
  23. ?>
  24. </div>
  25. <div class="rightcol">
cim
Witam,

wygląda jakbys miał problem z ostatnim apostrofem w tej linijce:
  1. echo '<img src="' . $dir . $img . '"/>';

Sprawdź czy jest, ew. napiszą tą linijkę od nowa, bo nawet kolorowanie składni na forum jakoś dziwnie ten apostrof traktuje.

Pozdrawiam

PS. jak nie zadziała to wklej kod HTML z 'Podaż źródło'
stern
źródło strony. kod php bez wklejania do html działa poprawnie :/
  1. <title>Galery</title>
  2. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" />
  3. <link rel="stylesheet" type="text/css" href="style2.css" />
  4. </head>
  5.  
  6. <body><div style="position: static; z-index:101;">
  7. <script type="text/javascript">
  8. window.google_analytics_uacct = "UA-1665446-6";
  9. <script type="text/javascript" src="http://img.ugu.pl/advert.js">
  10. </div>
  11.  
  12. <table width="100%" cellpadding="0" cellspacing="0" style="height:100%">
  13. <tr>
  14.  
  15. <td class="left"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
  16. <td class="middle">
  17. <p style="cursor:crosshair;"><img src="images/logo.gif" alt="" width="700" height="180" class="float" /></p>
  18. <div class="leftcol">
  19. <?php
  20. $dir = './art/';
  21. $exts = array( 'gif', 'jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'GIF', 'PNG' );
  22. $imgs = array();
  23. if( $d = opendir( $dir ) )
  24. {
  25. while( $f = readdir( $d ) )
  26. {
  27. $ext = explode( '.', $f );
  28. $ext = array_pop( $ext );
  29. if( in_array( strtolower( $ext ), $exts ) )
  30. {
  31. $imgs[] = $f;
  32. }
  33. }
  34. closedir( $d );
  35. }
  36.  
  37. $img = $imgs[ array_rand( $imgs ) ];
  38. echo '<img src="' . $dir . $img . '"/>';
  39. ?>
  40. </div>
  41. <div class="rightcol">
  42. <div class="group">
  43. <a target="_blank" href="art/CCI_00000.jpg"><img src="art/CCI_00000.jpg" alt="Girl" width="57" height="78" /></a>
  44. <a target="_blank" href="art/CCI_00001.jpg"><img src="art/CCI_00001.jpg" alt="Girl" width="57" height="78" /></a>
  45.  
  46. <a target="_blank" href="art/CCI_00002.jpg"><img src="art/CCI_00002.jpg" alt="Girl" width="57" height="78" /></a>
  47. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  48. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  49. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  50. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  51. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  52. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  53. <a target="_blank" href="#"><img src="" alt="" width="57" height="57" /></a>
  54. </div>
  55.  
  56. </div>
  57. </td>
  58. <td class="right"><img src="images/spacer.gif" width="1" height="1" alt="" /></td>
  59. </tr>
  60. </table>
  61. <script type="text/javascript">
  62. var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  63. document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  64. <script type="text/javascript">
  65. try {
  66. var pageTracker = _gat._getTracker("UA-1665446-6");
  67. pageTracker._setDomainName("none");
  68. pageTracker._setAllowLinker(true);
  69. pageTracker._trackPageview();
  70. } catch(err) {}</script>
  71. </body>
  72. </html>


cim
Mhm, ok ale chodziło mi o to, żebyś otworzył w przeglądarce tą stronę (wtedy kiedy pokazuje się to '; ?>) i wtedy Widok -> Pokaź źródło strony. Może tam coś będzie widać

Pozdrawiam
stern
ok, tu jest stronka http://mist-sn.ugu.pl/galery.html
cim
Witam,

jeżeli w stronie HTML masz kod PHP to cały plik musi mieć rozszeżenie .php inaczej PHP nie jest w ogóle interpretowane.

Pozdrawiam
stern
Dziękuję cim. Teraz wszystko pięknie działa ^^

Pozdrawiam smile.gif
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.