Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Problem ze skryptem - głosowanie z MySQL
imatix
post 13.05.2010, 09:43:31
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

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 11:18