Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MYSQL]/[PHP], Błąd Select Max
InzaghiX
post
Post #1





Grupa: Zarejestrowani
Postów: 24
Pomógł: 0
Dołączył: 20.01.2008

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


Witam, mam taki problem odnośnie wyświetlenia wartości maksymalnej z kolumny gdy wyświetlam kod

  1. <?php
  2. $sql2 = "SELECT (id_film) FROM filmy";
  3. $result2 = mysql_query($sql2) or die( mysql_error() );
  4. while ($row = mysql_fetch_array($result2) )
  5.  echo "$row[id_film]<br/>";
  6.  mysql_free_result($result2);
  7. ?>


A jak chce zrobić aby wyświetliło maksymalna wartość kolumny i powiększyło ją o 1 w góre to nic nie wyświetla

  1. <?php
  2. $sql2 = "SELECT MAX(id_film)+1 FROM filmy";
  3. $result2 = mysql_query($sql2) or die( mysql_error() );
  4. while ($row = mysql_fetch_array($result2) )
  5.  echo "$row[id_film]<br/>";
  6.  mysql_free_result($result2);
  7. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
-Wieviór-
post
Post #2





Goście







Zrób tak:
  1. <?php
  2. $sql = "SELECT * FROM filmy ORDER BY id_film DESC LIMIT 1";
  3. $result = mysql_query($sql) or die(mysql_error());
  4. $row = mysql_fetch_array($result);
  5.  
  6. $numer = $row[id_film]+1;
  7. echo $numer.'<br/>';
  8.  
  9. $sql2 = "UPDATE filmy SET id_film=id_film+1 WHERE id='".$row[id_film]."'";
  10. mysql_query($sql2) or die(mysql_error());
  11. ?>
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: 10.10.2025 - 04:01