Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [MySQL][PHP]Bind Param
Waloch016
post
Post #1





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Czy ktos moze zerknac co tu jest nie tak w kodzie?? Zaznaczam ze wszystkie kolumny w bazie istnieja. i laczyc tez sie laczy bo bledy nie wywala.
  1. <?php
  2. //include database connection
  3. $servername = "localhost";
  4. $username = "root";
  5. $password = "";
  6. $dbname = "system";
  7.  
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10. // Check connection
  11. if ($conn->connect_error) {
  12. die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. // if the form was submitted/posted, update the record
  16. if($_POST){
  17.  
  18. //write query
  19. $stmt = $conn->prepare("UPDATE
  20. booking
  21. VALUES
  22. car = ?,
  23. date = ?,
  24. time = ?,
  25. number = ?,
  26. name = ?,
  27. type = ?,
  28. price = ?
  29. WHERE
  30. id = ?");
  31.  
  32.  
  33. // you can bind params this way,
  34. // if you want to see the other way, see our add.php
  35. $stmt->bind_param(
  36. 'sssissii',
  37. $_POST['$car'],
  38. $_POST['$date'],
  39. $_POST['$time'],
  40. $_POST['$number'],
  41. $_POST['$name'],
  42. $_POST['$type'],
  43. $_POST['$price'],
  44. $_GET['$id']
  45. );
  46.  
  47. // execute the update statement
  48. if($stmt->execute()){
  49. echo "User was updated.";
  50.  
  51. // close the prepared statement
  52. $stmt->close();
  53. }else{
  54. die("Unable to update.");
  55. }
  56. }
  57.  
  58. /*
  59.  * select the record to be edited,
  60.  * you can also use prepared statement here,
  61.  * but my hosting provider seems it does not support the mysqli get_result() function
  62.  
  63.  * so it I'm going to use $mysqli->real_escape_string() this time.
  64.  */
  65.  
  66. $sql = "SELECT
  67. id, car, date, time, number, name, type, price
  68. FROM
  69. booking
  70. WHERE
  71. id = \"" . $conn->real_escape_string($_GET['id']) . "\"
  72. LIMIT
  73. 0,1";
  74.  
  75.  
  76. // execute the sql query
  77. $result = $conn->query($sql);
  78.  
  79. //get the result
  80. $row = $result->fetch_assoc();
  81.  
  82. // php's extract() makes $row['firstname'] to $firstname automatically
  83. extract($row);
  84.  
  85. //disconnect from database
  86. $result->free();
  87. $conn->close();
  88. ?>
  89.  
  90. <!--we have our html form here where new user information will be entered-->
  91. <form action='edit.php?id=<?php echo $id; ?>' method='post' border='0'>
  92. <fieldset>
  93. <dl>
  94. <dt><label for="car" >Car Make:</label></dt>
  95. <dd><input name="car" type="text" value="<?php echo $car; ?>"></dd>
  96. <dt><label for="date">Date:</label></dt>
  97. <dd><input name="date" type="text" id="datepicker" value="<?php echo $date; ?>"></dd>
  98. <dt><label for="time">Arrive Time:</label></dt>
  99. <dd><input name="time" type="text" placeholder="13:00" value="<?php echo $time; ?>"></dd>
  100. <dt><label for="number">Tel. No.:</label></dt>
  101. <dd><input name="number" type="text" value="<?php echo $number; ?>"></dd>
  102. <dt><label for="name">Name:</label></dt>
  103. <dd><input name="name" type="text" value="<?php echo $name; ?>"></dd>
  104. <dt><label for="type" style="width:450px;">Type:</label></dt>
  105. <dd><select name="type" value="<?php echo $type; ?>">
  106. <option value="0">Select</option>
  107. <option value="Wash + Vac">Wash + Vac</option>
  108. <option value="Mini Valet">Mini Valet</option>
  109. <option value="Full Valet">Full Valet</option>
  110. <option value="Detar">Detar</option>
  111. <option value="Other">Other</option>
  112. </select></dd>
  113. <dt><label for="price">Price:</label></dt>
  114. <dd><select name="price" value="<?php echo $price; ?>">
  115. <option value="0">Select</option>
  116. <option value="10">? 10</option>
  117. <option value="15">? 15</option>
  118. <option value="20">? 20</option>
  119. <option value="25">? 25</option>
  120. <option value="30">? 30</option>
  121. <option value="35">? 35</option>
  122. <option value="40">? 40</option>
  123. <option value="45">? 45</option>
  124. <option value="50">? 50</option>
  125. <option value="55">? 55</option>
  126. <option value="60">? 60</option>
  127. <option value="65">? 65</option>
  128. <option value="70">? 70</option>
  129. <option value="75">? 75</option>
  130. <option value="80">? 80</option>
  131. <option value="85">? 85</option>
  132. <option value="90">? 90</option>
  133. <option value="95">? 95</option>
  134. <option value="100">? 100</option>
  135. <option value="105">? 105</option>
  136. <option value="110">? 110</option>
  137. <option value="115">? 115</option>
  138. <option value="120">? 120</option>
  139. <option value="125">? 125</option>
  140. <option value="130">? 130</option>
  141. </select></dd>
  142. <dt><input type="submit" name="submit" value="Add"></dt></dl>
  143. </fieldset>
  144. </form>
  145.  
  146. </body>
  147. </html>

Szukalem w google, siedze 3 dzien i nie moge nic wyyslic. id, number, price to jest INT w bazie

Zapomnialem, przepraszam: Fatal error: Call to a member function bind_param() on a non-object in C:\wamp\www\edit.php on line 35

Wiem co znaczy blad, nie wiem jak naprawic. tak w razie w to pisze

Ten post edytował Waloch016 19.11.2014, 11:42:13
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Czy naprawde to taki problem napisać, czym objawia się błąd?
Go to the top of the page
+Quote Post
Turson
post
Post #3





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


http://stackoverflow.com/questions/1705346...my-mysqli-query
Policz ile masz ? a ile danych bindujesz.
Go to the top of the page
+Quote Post
nospor
post
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Zanim zadasz kolejne pytanie zastosuj sie tez do tego:
Temat: Jak poprawnie zada pytanie
Bo masz procz tego co napisał Turson całą masę innych błędów, ale ich nie widzisz, bo nie wyswietlasz ich na ekranie
Go to the top of the page
+Quote Post
Waloch016
post
Post #5





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Włączyłem raportowanie i dalej wywala tylko bind param a jak z bind param usunalem id dalej to samo.

Ten post edytował Waloch016 19.11.2014, 11:47:42
Go to the top of the page
+Quote Post
nospor
post
Post #6





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Bo FATAL ERROR powoduje, ze nie dochodzisz do pozostalych bledow. Jak sie uporasz z FATAL ERROREM, to zobaczysz inne bledy (IMG:style_emoticons/default/smile.gif)

Zobacz co zwraca ci PREPARE a moze doznasz olsnienia.
Go to the top of the page
+Quote Post
Waloch016
post
Post #7





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Nie wiem co jest grane... nie daje rady juz kod mi sie w oczach wli..
Go to the top of the page
+Quote Post
Turson
post
Post #8





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Po prostu zobacz w manualu MySQL jak UPDATE powinien wyglądać
Go to the top of the page
+Quote Post
Waloch016
post
Post #9





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Ok, mam ale danych w bazie nie zmienia...
Go to the top of the page
+Quote Post
nospor
post
Post #10





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Po pierwsze: pokaz kod po poprawkach
Po drugie: a poprawiles bledy o ktorych mowilem? Te bledy, ktore mialy ci sie pojawic po zastosowaniu do tematu, do ktorego cie odeslalem.
Go to the top of the page
+Quote Post
Waloch016
post
Post #11





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


  1. <?php
  2.  
  3. ini_set('display_errors','1');
  4. //include database connection
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. $dbname = "system";
  9.  
  10. // Create connection
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12. // Check connection
  13. if ($conn->connect_error) {
  14. die("Connection failed: " . $conn->connect_error);
  15. }
  16.  
  17. // if the form was submitted/posted, update the record
  18. if($_POST){
  19.  
  20. //write query
  21. //$stmt == TRUE
  22. $stmt = $conn->prepare("UPDATE
  23. `booking`
  24. SET
  25. car = ?,
  26. date = ?,
  27. time = ?,
  28. number = ?,
  29. name = ?,
  30. type = ?,
  31. price = ?
  32. WHERE
  33. id = ?");
  34. //var_dump($stmt);
  35.  
  36.  
  37. // you can bind params this way,
  38. // if you want to see the other way, see our add.php
  39. $stmt -> bind_param(
  40. 'sssissii',
  41. $_POST['$car'],
  42. $_POST['$date'],
  43. $_POST['$time'],
  44. $_POST['$number'],
  45. $_POST['$name'],
  46. $_POST['$type'],
  47. $_POST['$price'],
  48. $_POST['id']);
  49.  
  50. // execute the update statement
  51. if($stmt->execute()){
  52. echo "User was updated.";
  53. header('Location: booking.php');
  54.  
  55. // close the prepared statement
  56. $stmt->close();
  57. }else{
  58. die("Unable to update.");
  59. }
  60. }
  61.  
  62. /*
  63.  * select the record to be edited,
  64.  * you can also use prepared statement here,
  65.  * but my hosting provider seems it does not support the mysqli get_result() function
  66.  * you can use it like this one <a href="http://php.net/manual/fr/mysqli.prepare.php#107568" target="_blank">http://php.net/manual/fr/mysqli.prepare.php#107568</a>
  67.  
  68.  * so it I'm going to use $mysqli->real_escape_string() this time.
  69.  */
  70.  
  71. $sql = "SELECT
  72. id, car, date, time, number, name, type, price
  73. FROM
  74. `booking`
  75. WHERE
  76. id = \"" . $conn->real_escape_string($_GET['id']) . "\"
  77. LIMIT
  78. 0,1";
  79.  
  80.  
  81. // execute the sql query
  82. $result = $conn->query($sql);
  83.  
  84. //get the result
  85. $row = $result->fetch_assoc();
  86.  
  87. // php's extract() makes $row['firstname'] to $firstname automatically
  88. extract($row);
  89.  
  90. //disconnect from database
  91. $result->free();
  92. $conn->close();
  93. ?>
  94.  
  95. <!--we have our html form here where new user information will be entered-->
  96. <form action='edit.php?id=<?php echo $id; ?>' method='post' border='0'>
  97. <fieldset>
  98. <dl>
  99. <dt><label for="car" >Car Make:</label></dt>
  100. <dd><input name="car" type="text" value="<?php echo $car; ?>"></dd>
  101. <dt><label for="date">Date:</label></dt>
  102. <dd><input name="date" type="text" id="datepicker" value="<?php echo $date; ?>"></dd>
  103. <dt><label for="time">Arrive Time:</label></dt>
  104. <dd><input name="time" type="text" placeholder="13:00" value="<?php echo $time; ?>"></dd>
  105. <dt><label for="number">Tel. No.:</label></dt>
  106. <dd><input name="number" type="text" value="<?php echo $number; ?>"></dd>
  107. <dt><label for="name">Name:</label></dt>
  108. <dd><input name="name" type="text" value="<?php echo $name; ?>"></dd>
  109. <dt><label for="type" style="width:450px;">Type:</label></dt>
  110. <dd><select name="type" value="<?php echo $type; ?>">
  111. <option value="0">Select</option>
  112. <option value="Wash + Vac">Wash + Vac</option>
  113. <option value="Mini Valet">Mini Valet</option>
  114. <option value="Full Valet">Full Valet</option>
  115. <option value="Detar">Detar</option>
  116. <option value="Other">Other</option>
  117. </select></dd>
  118. <dt><label for="price">Price:</label></dt>
  119. <dd><select name="price" value="<?php echo $price; ?>">
  120. <option value="0">Select</option>
  121. <option value="10">&euro; 10</option>
  122. <option value="15">&euro; 15</option>
  123. <option value="20">&euro; 20</option>
  124. <option value="25">&euro; 25</option>
  125. <option value="30">&euro; 30</option>
  126. <option value="35">&euro; 35</option>
  127. <option value="40">&euro; 40</option>
  128. <option value="45">&euro; 45</option>
  129. <option value="50">&euro; 50</option>
  130. <option value="55">&euro; 55</option>
  131. <option value="60">&euro; 60</option>
  132. <option value="65">&euro; 65</option>
  133. <option value="70">&euro; 70</option>
  134. <option value="75">&euro; 75</option>
  135. <option value="80">&euro; 80</option>
  136. <option value="85">&euro; 85</option>
  137. <option value="90">&euro; 90</option>
  138. <option value="95">&euro; 95</option>
  139. <option value="100">&euro; 100</option>
  140. <option value="105">&euro; 105</option>
  141. <option value="110">&euro; 110</option>
  142. <option value="115">&euro; 115</option>
  143. <option value="120">&euro; 120</option>
  144. <option value="125">&euro; 125</option>
  145. <option value="130">&euro; 130</option>
  146. </select></dd>
  147. <dt><input type="submit" name="submit" value="Add"></dt></dl>
  148. </fieldset>
  149. </form>
  150.  
  151. </body>
  152. </html>


Nie wywala mi bledow nic a nic
Go to the top of the page
+Quote Post
nospor
post
Post #12





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Wywal to:
header('Location: booking.php');

Nadal nie masz bledow na ekranie?
Go to the top of the page
+Quote Post
Waloch016
post
Post #13





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Ani jednego. Tylko wyswietla ze jest updated ale nie robi update bazy

Ten post edytował Waloch016 19.11.2014, 12:52:55
Go to the top of the page
+Quote Post
nospor
post
Post #14





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Niemozliwe.... przeciez o to:
$_POST['$car'],
$_POST['$date'],
$_POST['$time'],
$_POST['$number'],
.....

Powinno rzucac samymi NOTICEami.... przeciez nie masz w POST takich pol
Go to the top of the page
+Quote Post
Waloch016
post
Post #15





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Kompletnie ani jednego bledu.
  1. // execute the update statement
  2. if($stmt->execute() === TRUE){
  3. echo "User was updated.";
  4. //header('Location: booking.php');
  5.  
  6. // close the prepared statement
  7. $stmt->close();
  8. }else{
  9. die("Unable to update.");
  10. }
  11. }


Dalem tak ale dalej bez reakcji
Go to the top of the page
+Quote Post
nospor
post
Post #16





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Napisalem ci gdzie masz blad
Dane typu $_POST['$car'],
nie istnieją. Nie masz w formularzu takich pol. Staraj sie prosze czytac dokladniej co ci piszą.

A to ze nie widzisz tych bledow to nadal niemozliwe. No chyba ze masz jakąś wlasną funkcje do obslugi bledow, ale tego w kodzie nie widac.

Bledow tych mozesz tez nie widziec, bo moze masz zwaloną strukture HTML i one są gdzies czyms zasloniete. Pewnie w kodzie wygenerowanej strony juz je zobaczysz.
Go to the top of the page
+Quote Post
Waloch016
post
Post #17





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Mam Noticy. Próbuje tak:

  1. <?php
  2.  
  3. ini_set('display_errors','1');
  4. //include database connection
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. $dbname = "system";
  9.  
  10. // Create connection
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12. // Check connection
  13. if ($conn->connect_error) {
  14. die("Connection failed: " . $conn->connect_error);
  15. }
  16. if(isset($_POST['car']) && isset($_POST['date']) && isset($_POST['time']) && isset($_POST['number']) && isset($_POST['name']) && isset($_POST['type']) && isset($_POST['price']))
  17. {
  18. $car = $_POST['car'];
  19. $date = $_POST['date'];
  20. $time = $_POST['time'];
  21. $number = $_POST['number'];
  22. $name = $_POST['name'];
  23. $type = $_POST['type'];
  24. $price = $_POST['price'];
  25. }
  26. else
  27. {
  28. echo 'inny';
  29. }
  30.  
  31. // if the form was submitted/posted, update the record
  32. if($_POST){
  33.  
  34. //write query
  35. //$stmt == TRUE
  36. $stmt = $conn->prepare("UPDATE
  37. `booking`
  38. SET
  39. car = ?,
  40. date = ?,
  41. time = ?,
  42. number = ?,
  43. name = ?,
  44. type = ?,
  45. price = ?
  46. WHERE
  47. id = ?");
  48.  
  49. //var_dump($stmt);
  50.  
  51.  
  52. // you can bind params this way,
  53. // if you want to see the other way, see our add.php
  54. $stmt -> bind_param(
  55. 'sssissii',
  56. $_POST['$car'],
  57. $_POST['$date'],
  58. $_POST['$time'],
  59. $_POST['$number'],
  60. $_POST['$name'],
  61. $_POST['$type'],
  62. $_POST['$price'],
  63. $_POST['id']);
  64.  
  65. // execute the update statement
  66. if($stmt->execute() === TRUE){
  67. echo "User was updated.";
  68. //header('Location: booking.php');
  69.  
  70. // close the prepared statement
  71. $stmt->close();
  72. }else{
  73. die("Unable to update.");
  74. }
  75. }
  76. /*
  77.  * select the record to be edited,
  78.  * you can also use prepared statement here,
  79.  * but my hosting provider seems it does not support the mysqli get_result() function
  80.  * you can use it like this one <a href="http://php.net/manual/fr/mysqli.prepare.php#107568" target="_blank">http://php.net/manual/fr/mysqli.prepare.php#107568</a>
  81.  
  82.  * so it I'm going to use $mysqli->real_escape_string() this time.
  83.  */
  84.  
  85. $sql = "SELECT
  86. id, car, date, time, number, name, type, price
  87. FROM
  88. `booking`
  89. WHERE
  90. id = \"" . $conn->real_escape_string($_GET['id']) . "\"
  91. LIMIT
  92. 0,1";
  93.  
  94.  
  95. // execute the sql query
  96. $result = $conn->query($sql);
  97.  
  98. //get the result
  99. $row = $result->fetch_assoc();
  100.  
  101. // php's extract() makes $row['firstname'] to $firstname automatically
  102. extract($row);
  103.  
  104. //disconnect from database
  105. $result->free();
  106. $conn->close();
  107. ?>
  108.  
  109. <?php
  110. if(isset($_POST['car']) && isset($_POST['date']) && isset($_POST['time']) && isset($_POST['number']) && isset($_POST['name']) && isset($_POST['type']) && isset($_POST['price']))
  111. {
  112. echo'<section id="main">
  113. <form action="edit.php?id=<?php echo $id; ?>" method="post">
  114. <fieldset>
  115. <dl>
  116.  
  117. <input type="hidden" name="id" value="<?php echo $id; ?>" />
  118. <dt><label for="car">Car Make:</label></dt>
  119. <dd><input name="car" type="text"></dd>
  120. <dt><label for="date">Date:</label></dt>
  121. <dd><input name="date" type="text" id="datepicker" ></dd>
  122. <dt><label for="time">Arrive Time:</label></dt>
  123. <dd><input name="time" type="text" placeholder="13:00"></dd>
  124. <dt><label for="number">Tel. No.:</label></dt>
  125. <dd><input name="number" type="text"></dd>
  126. <dt><label for="name">Name:</label></dt>
  127. <dd><input name="name" type="text"></dd>
  128. <dt><label for="type" style="width:450px;">Type:</label></dt>
  129. <dd><select name="type">
  130. <option value="0">Select</option>
  131. <option value="Wash + Vac">Wash + Vac</option>
  132. <option value="Mini Valet">Mini Valet</option>
  133. <option value="Full Valet">Full Valet</option>
  134. <option value="Detar">Detar</option>
  135. <option value="Other">Other</option>
  136. </select></dd>
  137. <dt><label for="price">Price:</label></dt>
  138. <dd><select name="price">
  139. <option value="0">Select</option>
  140. <option value="10">? 10</option>
  141. <option value="15">? 15</option>
  142. <option value="20">? 20</option>
  143. <option value="25">? 25</option>
  144. <option value="30">? 30</option>
  145. <option value="35">? 35</option>
  146. <option value="40">? 40</option>
  147. <option value="45">? 45</option>
  148. <option value="50">? 50</option>
  149. <option value="55">? 55</option>
  150. <option value="60">? 60</option>
  151. <option value="65">? 65</option>
  152. <option value="70">? 70</option>
  153. <option value="75">? 75</option>
  154. <option value="80">? 80</option>
  155. <option value="85">? 85</option>
  156. <option value="90">? 90</option>
  157. <option value="95">? 95</option>
  158. <option value="100">? 100</option>
  159. <option value="105">? 105</option>
  160. <option value="110">? 110</option>
  161. <option value="115">? 115</option>
  162. <option value="120">? 120</option>
  163. <option value="125">? 125</option>
  164. <option value="130">? 130</option>
  165. </select></dd>
  166. <dt><input type="submit" name="submit" value="Add"></dt></dl>
  167. </fieldset>
  168. </form>
  169. </section>';
  170. }
  171. else
  172. {
  173. echo 'Blad';
  174. }
  175. ?>
  176. </body>
  177. </html>

Nie idzie. Dlaczego??

Ten post edytował Waloch016 19.11.2014, 13:55:04
Go to the top of the page
+Quote Post
nospor
post
Post #18





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




(IMG:style_emoticons/default/facepalmxd.gif)
$_POST['$car'],
Nadal odwolujesz sie do pol, ktorych nie ma....

kurcze, naprawde nie rozrozniasz
$car
od
car
?

Analogicznie reszta
Go to the top of the page
+Quote Post
Waloch016
post
Post #19





Grupa: Zarejestrowani
Postów: 110
Pomógł: 0
Dołączył: 2.10.2010
Skąd: Irlandia

Ostrzeżenie: (0%)
-----


Mój błąd nie zauwazylem tego. Tak jak powiedzialem juz mi leb peka ;p Ale mam następne pytanko (IMG:style_emoticons/default/wink.gif)

Mam taki kod wyswietlania:

  1. <?php
  2. include_once('db.php');
  3.  
  4. $query = "SELECT * FROM booking ORDER BY date";
  5. $result = $conn -> query($query)
  6. or die("Query failed");
  7. ?>
  8. <table rules="rows" frame="below" width="100%">
  9. <tr>
  10. <td bgcolor="#e6e6e6"> </td>
  11. <td bgcolor="#e6e6e6">Car:</td>
  12. <td bgcolor="#e6e6e6">Date:</td>
  13. <td bgcolor="#e6e6e6">Time:</td>
  14. <td bgcolor="#e6e6e6">Number:</td>
  15. <td bgcolor="#e6e6e6">Name:</td>
  16. <td bgcolor="#e6e6e6">Price:</td>
  17. </tr>
  18. <?php
  19. while ($row = mysqli_fetch_array($result)){
  20. echo "<tr><td>" . $row['id'] . "</td>" .
  21. "<td>" . $row['car'] . "</td>" .
  22. "<td>" . $row['date'] . "</td>" .
  23. "<td>" . $row['time'] . "</td>" .
  24. "<td>" . $row['number'] . ".</td>" .
  25. "<td>" . $row['name'] . "</td>" .
  26. "<td>" . $row['type'] . "</td>" .
  27. "<td>" . $row['price'] . " ?</td></tr>";
  28.  
  29. }
  30. ?>
  31. </table>


Działa to idealnie. Moje pytanie jest takie jak wyswetlic zeby co drugi rekord (linia) mial inny kolor. np. szary-bialy-szary-bialy itd... nigdy w sumie nie stylowalem tabeli i sie z nimi nie bawilem wiec nie do konca wiem...

Ten post edytował Waloch016 19.11.2014, 14:23:34
Go to the top of the page
+Quote Post
Turson
post
Post #20





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

Ostrzeżenie: (0%)
-----


Załatwisz to w CSS nth-child albo w PHP definiujesz zmienną $i przed pętlą, liczysz modulo w petli i inkrementujesz
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 27.08.2025 - 05:52