Niestety, po kilku zabiegach stanęło na tym, że zdjęcie niby się dodaje, w bazie jest widoczne, lecz brak nazwy i zamiast widocznego obrazka jest pusta ramka.
Druga kwestia to komentarze pod "parami" zdjęć, jak to sklecić?
Poniżej pliki:
functions.php
<?php // Calculate the expected % outcome function expected($Rb, $Ra) { return 1/(1 + pow(10, ($Rb-$Ra)/400)); } // Calculate the new winnner score function win($score, $expected, $k = 24) { return $score + $k * (1-$expected); } // Calculate the new loser score function loss($score, $expected, $k = 24) { return $score + $k * (0-$expected); } ?>
index.php
<?php include('mysql.php'); include('functions.php'); // Get random 2 $query="SELECT * FROM images ORDER BY RAND() LIMIT 0,2"; $images[] = (object) $row; } // Get the top10 $result = mysql_query("SELECT *, ROUND(score/(1+(losses/wins))) AS performance FROM images ORDER BY ROUND(score/(1+(losses/wins))) DESC LIMIT 0,10"); // Close the connection ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Facemash-Alike Script</title> <style type="text/css"> body, html {font-family:Arial, Helvetica, sans-serif;width:100%;margin:0;padding:0;text-align:center;} h1 {background-color:#600;color:#fff;padding:20px 0;margin:0;} a img {border:0; height:300px; width:500px;} td {font-size:11px;} .image {background-color:#eee;border:1px solid #ddd;border-bottom:1px solid #bbb;padding:5px;} </style> </head> <body> <h1>FACEMASH-ALIKE</h1> <h3>Were we let in for our looks? No. Will we be judged on them? Yes.</h3> <h2>Who's hotter? Click to choose.</h2> <center> <table> <tr> <td valign="top" class="image"><a h[spam]"rate.php?winner=<?=$images[0]->image_id?>&loser=<?=$images[1]->image_id?>"><img src="images/<?=$images[0]->filename?>" /></a></td> <td valign="top" class="image"><a h[spam]"rate.php?winner=<?=$images[1]->image_id?>&loser=<?=$images[0]->image_id?>"><img src="images/<?=$images[1]->filename?>" /></a></td> </tr> <tr> <td>Won: <?=$images[0]->wins?>, Lost: <?=$images[0]->losses?></td> <td>Won: <?=$images[1]->wins?>, Lost: <?=$images[1]->losses?></td> </tr> <tr> <td>Score: <?=$images[0]->score?></td> <td>Score: <?=$images[1]->score?></td> </tr> <tr> </tr> </table> </center> <h2>Top Rated</h2> <center> <table> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top"><img src="images/<?=$image->filename?>" width="70" /></td> <? endforeach ?> </tr> <? /* Remove this to see the scoring <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Score: <?=$image->score?></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Performance: <?=$image->performance?></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Won: <?=$image->wins?></td> <? endforeach ?> </tr> <tr> <? foreach($top_ratings as $key => $image) : ?> <td valign="top">Lost: <?=$image->losses?></td> <? endforeach ?> </tr> */ ?> </table> </center> </body> </html>
mysql.php
<?php $user = "root"; $password = ""; $database = "baza"; $host = "localhost"; ?>
rate.php
<?php include('mysql.php'); include('functions.php'); // If rating - update the database if ($_GET['winner'] && $_GET['loser']) { // Get the winner // Get the loser // Update the winner score $winner_expected = expected($loser->score, $winner->score); $winner_new_score = win($winner->score, $winner_expected); //test print "Winner: ".$winner->score." - ".$winner_new_score." - ".$winner_expected."<br>"; mysql_query("UPDATE images SET score = ".$winner_new_score.", wins = wins+1 WHERE image_id = ".$_GET['winner']); // Update the loser score $loser_expected = expected($winner->score, $loser->score); $loser_new_score = loss($loser->score, $loser_expected); //test print "Loser: ".$loser->score." - ".$loser_new_score." - ".$loser_expected."<br>"; mysql_query("UPDATE images SET score = ".$loser_new_score.", losses = losses+1 WHERE image_id = ".$_GET['loser']); // Insert battle // Back to the frontpage } ?>
no i plik do ładowania obrazków (domyślnie):
install_images.php
<?php include('mysql.php'); /* This is the correct way to loop over the directory. */ if($file!='.' && $file!='..') { $images[] = "('".$file."')"; } } } } else { } ?>
po moich zabiegach:
<?php include('mysql.php'); $images=$_POST['images']; $query = "INSERT INTO images (filename) VALUES ('$images')"; //$query = "INSERT INTO przedmioty VALUES ('','$nazwa','$wykladowca')"; ?>
do tego formularz:
<?php echo "<input type='hidden' name='MAX_FILE_SIZE' value='32500' />"; /* maksymalna wielkość pliku w bajtach */ ?>
MySQL:
CREATE TABLE IF NOT EXISTS `battles` ( `battle_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `winner` bigint(20) UNSIGNED NOT NULL, `loser` bigint(20) UNSIGNED NOT NULL, PRIMARY KEY (`battle_id`), KEY `winner` (`winner`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; CREATE TABLE IF NOT EXISTS `images` ( `image_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, `filename` varchar(255) NOT NULL, `score` int(10) UNSIGNED NOT NULL DEFAULT '1500', `wins` int(10) UNSIGNED NOT NULL DEFAULT '0', `losses` int(10) UNSIGNED NOT NULL DEFAULT '0', PRIMARY KEY (`image_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Aby umieścić zdjęcia w bazie, trzeba stworzyć folder "images" i tam je wrzucić, następnie plikiem install_images.php ładuje fotki...
Pogrzebie ktoś w tym?