Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Łączenie z bazą danych
kosior11
post
Post #1





Grupa: Zarejestrowani
Postów: 101
Pomógł: 0
Dołączył: 20.03.2011

Ostrzeżenie: (10%)
X----


  1. <table width=580px align="top" border="10">
  2.  
  3. <tr>
  4. <td><a href="dodaj.php"><img src="html/dodaj.jpg"></a></td>
  5.  
  6. <tr bgcolor="#FF6600">
  7. <td>kategoria 1</td>
  8. <tr>
  9. <td>
  10. <table width=580>
  11.  
  12. <?php
  13. [b]include("polacz.php");[/b]
  14. $query = mysql_query("select * from news WHERE `kat_id` = '1'");
  15. while($rekord = mysql_fetch_array($query))
  16. {
  17. $naz .= '<table><img src="html/f_6.jpg"><a href="news.php?id='.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'<br><center><img src="html/linia.jpg"></center></br></table>';
  18.  
  19. echo '<tr>'.$naz.'</tr>';
  20.  
  21. }
  22. ?>
  23.  
  24. </td>
  25. <tr>
  26. <td><a href="ekstra.php">(więcej)</a></td>
  27. </tr>
  28.  
  29.  
  30.  
  31.  
  32. <tr bgcolor="#FF6600">
  33. <td>kategoria 2</td>
  34. <tr>
  35. <td>
  36. <table width=580>
  37.  
  38. <?php
  39. [b]include("polacz.php");[/b]
  40. $query = mysql_query("select * from news WHERE `kat_id` = '2'");
  41. while($rekord = mysql_fetch_array($query))
  42. {
  43. $naz .= '<table><img src="html/f_1.gif"><a href="news.php?id='.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'<br><center><img src="html/linia.jpg"></center></br></table>';
  44.  
  45. echo '<tr>'.$naz.'</tr>';
  46. }
  47. ?>
  48.  
  49. </td>
  50. </tr>
  51.  
  52. <tr bgcolor="#FF6600">
  53. <td>kategoria 3</td>
  54. <tr>
  55. <td>
  56. <table width=580>
  57.  
  58. <?php
  59. [b]include("polacz.php"); [/b]
  60. $query = mysql_query("select * from news WHERE `kat_id` = '3'");
  61. while($rekord = mysql_fetch_array($query))
  62. {
  63. $naz .= '<table><img src="html/f_2.jpg"><a href="news.php?id='.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'<br><center><img src="html/linia.jpg"></center></br></table>';
  64.  
  65. echo '<tr>'.$naz.'</tr>';
  66. }
  67. ?>
  68.  
  69. </td>
  70. </tr>
  71.  
  72. <tr bgcolor="#FF6600">
  73. <td>kategoria 4</td>
  74. <tr>
  75. <td>
  76. <table width=580>
  77.  
  78. <?php
  79. [b]include("polacz.php"); [/b]
  80. $query = mysql_query("select * from news WHERE `kat_id` = '4'");
  81. while($rekord = mysql_fetch_array($query))
  82. {
  83. $naz .= '<table><img src="html/f_3.jpg"><a href="news.php?id='.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'<br><center><img src="html/linia.jpg"></center></br></table>';
  84.  
  85. echo '<tr>'.$naz.'</tr>';
  86. }
  87. ?>
  88.  
  89.  
  90. </td>
  91. </tr>
  92.  
  93. <tr bgcolor="#FF6600">
  94. <td>kategoria 5</td>
  95. <tr>
  96. <td>
  97. <table width=580>
  98.  
  99. <?php
  100. [b]include("polacz.php"); [/b]
  101. $query = mysql_query("select * from news WHERE `kat_id` = '5'");
  102. while($rekord = mysql_fetch_array($query))
  103. {
  104. $naz .= '<table><img src="html/f_4.jpg"><a href="news.php?id='.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'<br><center><img src="html/linia.jpg"></center></br></table>';
  105.  
  106. echo '<tr>'.$naz.'</tr>';
  107. }
  108. ?>
  109.  
  110. </td>
  111. </tr>
  112.  
  113. <tr bgcolor="#FF6600">
  114. <td>kategoria 6</td>
  115. <tr>
  116. <td>
  117. <table width=580>
  118.  
  119.  
  120. <?php
  121. [b]include("polacz.php"); [/b]
  122. $query = mysql_query("select * from news WHERE `kat_id` = '6'");
  123. while($rekord = mysql_fetch_array($query))
  124. {
  125. $naz .= '<table><img src="html/f_5.jpg"><a href="news.php?id='.$rekord[0].'">'.$rekord[1].'</a> Autor: '.$rekord[3].' - '.$rekord[2].'<br><center><img src="html/linia.jpg"></center></br></table>';
  126.  
  127. echo '<tr>'.$naz.'</tr>';
  128. }
  129. ?>
  130.  
  131. </td>
  132. </tr>
  133. </table>
  134. </table>
  135. </table></table></table></table></table>


Jak zapisać ten kod żeby tylko raz się łączyć z bazą a nie kilka razy jak jest w moim przykładzie
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.09.2025 - 09:04