Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Problem ze skryptem - głosowanie z MySQL
imatix
post
Post #1





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 19.10.2008

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


Może ktos wie czemu ten skrypt nie działa?? :

  1. <?php
  2. // Connects to your Database
  3. mysql_connect("mysql1.yoyo.pl", "dbxxxxxx", "haslo") or die(mysql_error());
  4. mysql_select_db("dbxxxxxx") or die(mysql_error());
  5.  
  6. //We only run this code if the user has just clicked a voting link
  7. if ( $mode=="vote")
  8. {
  9.  
  10. //If the user has already voted on the particular thing, we do not allow them to vote again $cookie = "Mysite$id";
  11. if(isset($_COOKIE[$cookie]))
  12. {
  13. Echo "Sorry You have already ranked that site <p>";
  14. }
  15.  
  16. //Otherwise, we set a cooking telling us they have now voted
  17. else
  18. {
  19. $month = 2592000 + time();
  20. setcookie(Mysite.$id, Voted, $month);
  21.  
  22. //Then we update the voting information by adding 1 to the total votes and adding their vote (1,2,3,etc) to the total rating
  23. mysql_query ("UPDATE vote SET total = total+$voted, votes = votes+1 WHERE id = $id");
  24. Echo "Your vote has been cast <p>";
  25. }
  26. }
  27.  
  28. //Puts SQL Data into an array
  29. $data = mysql_query("SELECT * FROM vote") or die(mysql_error());
  30.  
  31. //Now we loop through all the data
  32. while($ratings = mysql_fetch_array( $data ))
  33. {
  34.  
  35. //This outputs the sites name
  36. Echo "Name: " .$ratings['name']."<br>";
  37.  
  38. //This calculates the sites ranking and then outputs it - rounded to 1 decimal
  39. $current = $ratings[total] / $ratings[votes];
  40. Echo "Current Rating: " . round($current, 1) . "<br>";
  41.  
  42. //This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular item
  43. Echo "Rank Me: ";
  44. Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&id=".$ratings[id].">Vote 1</a> | ";
  45. Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=2&id=".$ratings[id].">Vote 2</a> | ";
  46. Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=3&id=".$ratings[id].">Vote 3</a> | ";
  47. Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&id=".$ratings[id].">Vote 4</a> | ";
  48. Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=5&id=".$ratings[id].">Vote 5</a><p>";
  49. }
  50.  
  51.  
  52. ?>


Wczesniej dodalem do bazy danych :
  1. CREATE TABLE vote (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30), total INTEGER, votes INTEGER)

oraz
  1. INSERT INTO vote (name, total, votes) VALUES ( "First item", 45, 10 ), ( "Second item", 15, 4 ), ( "Third thing", 25, 7 ), ( "The Forth", 20, 5 ), ( "Fifth Thing", 0, 0 )


Na stronie wszystko sie wyswietla, ale skrypt nie liczy sredniej, po kliknieciu nic sie nie zmienia:
Adres do skryptu http://www.muzycznalista.yoyo.pl/

Prosze o pomoc.
Pozdro

Ten post edytował imatix 13.05.2010, 09:44:06
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
imatix
post
Post #2





Grupa: Zarejestrowani
Postów: 34
Pomógł: 0
Dołączył: 19.10.2008

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


  1. //Wstawienie informacji z MySQL
  2. $data = mysql_query("SELECT *, total / votes AS average FROM vote ORDER BY average DESC") or die(mysql_error());
  3.  
  4. for($i = 1; $row = mysql_fetch_assoc($data); ++$i) {
  5. // i tutaj masz liczbę w zmiennej $i, co wiersz większą o 1
  6. }
  7. //Zapętlenie skryptu
  8. while($ratings = mysql_fetch_array( $data ))
  9. {
  10.  
  11. //Wykonawca
  12. Echo "<div id=lista><TABLE border=0 cellspacing=0 cellpadding=0><TR><TD><IMG SRC=img/nuta.jpg ALT=nuta></TD>
  13. <TD width=300px;>" .$ratings['wykonawca']." - ";
  14.  
  15. //Tytuł piosenki
  16. Echo "" .$ratings['tytul']."</TD>";
  17.  
  18. //Link do YouTube
  19. Echo "<TD width=50px;><a href=" .$ratings['adres']." target=_blank>Play</a></TD>";
  20.  
  21. //Wstawienie średniej arytmetycznej
  22. $current = $ratings['average'];
  23. Echo "<TD width=75px;>Ocena: " . round($current, 1) . "</TD>";


Cos mi sie strona nie chce wlaczac dalej
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: 7.10.2025 - 17:55