ziedinjsh Posted October 19, 2009 Report Share Posted October 19, 2009 (edited) Meklēju vienkāršu star rating systēmu.. skatījos šajā lapa postus, nekas noderīgs nebija.. vandos pa google, hotscripts bet nu tur ir vai nu tādi kuriem es vnk nesaprotu kā piesaistīt pie mysql vai arī tādi kuriem ir daudz failu.. vajaga tādu vienkāršu. ieeju sadaļā users un tur parādās useri.. gribu uztaisīt user ratingu.. pie katra usera rādā 5 zvaigznītes. 1 2 3 4 5 vērtējumi.. kad novērtē parāas attiecīgi tik cik ir kopvērtējums tik ir zvaigznītes. es zinuka te neviens neko pa velti nedara, tapēc vnk jautrāju varbūt kaut kas ir tāds kaut kur vai arī izdomāt kaut kā, kā to uztaisīt. ar IP var 1x dienā novērtēt. uzbraucot uz svaigzni parādās citu krāsa zvaigzne tas būtu taka ar css Edited October 19, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
briedis Posted October 19, 2009 Report Share Posted October 19, 2009 Primitīvākais variants: <? list($total,$rating) = explode("|",file_get_contents("rating.txt")); if(isset($_GET['new'])){ $new = $_GET['new']; $rating = ($total * $rating + $new)/($total+1); $total++; file_put_contents("rating.txt","$total|$rating"); } ?> Voter count: <?=$total;?><br/> Rating: <?=$rating;?><br/> <a href="?new=1">1</a> | <a href="?new=2">2</a> | <a href="?new=3">3</a> | <a href="?new=4">4</a> | <a href="?new=5">5</a> Tas tā, ieskatam.. pārējo domāt pats, vai arī ceri, ka kāds priekšā visu pateiks :) Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 19, 2009 Author Report Share Posted October 19, 2009 (edited) dabuju vienu kodu ieliku pie users.php tagad izskatās šādi: <?php include "misc/config.php"; include "header.php"; include "left.php"; $rating = $_POST['rating']; $id = $_POST['id']; $result = mysql_query("SELECT * FROM users ORDER BY id DESC"); while($data = mysql_fetch_array($result)) { if($rating > 5 || $rating < 1) { echo"Rating can't be below 1 or more than 5"; } elseif(isset($_COOKIE['rated'.$id])) { echo"<div class='highlight'>Already Voted!</div>"; } else { setcookie("rated".$id, $id, time()+60*60*24*365); $total_ratings = $data['total_ratings']; $total_rating = $data['total_rating']; $current_rating = $data['rating']; $new_total_rating = $total_rating + $rating; $new_total_ratings = $total_ratings + 1; $new_rating = $new_total_rating / $new_total_ratings; // Lets run the queries. mysql_query("UPDATE users SET total_rating = '".$new_total_rating."' WHERE id = '".$id."'") or die(mysql_error()); mysql_query("UPDATE users SET rating = '".$new_rating."' WHERE id = '".$id."'") or die(mysql_error()); mysql_query("UPDATE users SET total_ratings = '".$new_total_ratings."' WHERE id = '".$id."'") or die(mysql_error()); echo"<div class='highlight'>Vote Recorded!</div>"; } echo "<table><tr>"; echo "<td>username</td><td>".$data['username']."</td>"; echo "</tr><tr>"; echo "<td>email</td><td>".$data['email']."</td>"; echo "<td>rating</td><td>"; $rating = $data[rating]; ?> <div class="floatleft"> <div id="rating_<?php echo $data[id]; ?>"> <span class="star_1"><img src="misc/rate1.gif" alt="" <?php if($rating > 0) { echo"class='hover'"; } ?> /></span> <span class="star_2"><img src="misc/rate1.gif" alt="" <?php if($rating > 1.5) { echo"class='hover'"; } ?> /></span> <span class="star_3"><img src="misc/rate1.gif" alt="" <?php if($rating > 2.5) { echo"class='hover'"; } ?> /></span> <span class="star_4"><img src="misc/rate1.gif" alt="" <?php if($rating > 3.5) { echo"class='hover'"; } ?> /></span> <span class="star_5"><img src="misc/rate1.gif" alt="" <?php if($rating > 4.5) { echo"class='hover'"; } ?> /></span> </div> </div> <div class="star_rating"> (Rated <strong><?php echo $rating; ?></strong> Stars) </div> <div class="clearleft"> </div> <?php echo "</td>"; echo "</tr></table>"; echo "<hr>"; } include "footer.php"; ?> viņš man met ārā šādas kļūdas: Notice: Undefined index: rating in /home/produc/public_html/mp3/1/users.php on line 6 Notice: Undefined index: id in /home/produc/public_html/mp3/1/users.php on line 7 Notice: Use of undefined constant rating - assumed 'rating' in /home/produc/public_html/mp3/1/users.php on line 52 line 6: $rating = (int)$_POST['rating']; line 7: $id = (int)$_POST['id']; line 52: $rating = (int)$data[rating]; Edited October 19, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 19, 2009 Report Share Posted October 19, 2009 Nu, ja - tur Tev tak nevienā vietā nav forma, kas nodod caur POST tādu "rating" vērtību. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 19, 2009 Author Report Share Posted October 19, 2009 (edited) vai tad šie nav? $rating = $_POST['rating']; $id = $_POST['id']; un tur vēl ir divi JS faili $(document).ready(function() { $("[id^=rating_]").hover(function() { rid = $(this).attr("id").split("_")[1]; $("#rating_"+rid).children("[class^=star_]").children('img').hover(function() { $("#rating_"+rid).children("[class^=star_]").children('img').removeClass("hover"); /* The hovered item number */ var hovered = $(this).parent().attr("class").split("_")[1]; while(hovered > 0) { $("#rating_"+rid).children(".star_"+hovered).children('img').addClass("hover"); hovered--; } }); }); $("[id^=rating_]").children("[class^=star_]").click(function() { var current_star = $(this).attr("class").split("_")[1]; var rid = $(this).parent().attr("id").split("_")[1]; $('#rating_'+rid).load({rating: current_star, id: rid}); }); }); un JQuery Edited October 19, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 19, 2009 Report Share Posted October 19, 2009 "Tie tur" ir koda rindiņas, kas mēģina _saņemt_ Vai esi pārliecināts, ka tas JavaScript visu nosūta kā nākas? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 19, 2009 Author Report Share Posted October 19, 2009 laikam jau ka nē.. jo bija šāda rindiņa: $('#rating_'+rid).load(send.php{rating: current_star, id: rid}); bet es visu uztaisīju vienā lapā Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 19, 2009 Report Share Posted October 19, 2009 ... tātad viss tagad iet, ja? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 19, 2009 Author Report Share Posted October 19, 2009 nē.. es uzliku atpakaļ kā bija, bet nu nekādu izmaiņu.. laikam jau jāmeklē kāds cits kods... Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 19, 2009 Report Share Posted October 19, 2009 Parasti jau tā ir, ka nestrādā, ja bāž kodus un nasaprot kas tur notiek. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.