TheMasterGeneral Posted August 6, 2015 Share Posted August 6, 2015 Pretty simple. Allows players to rate other players' posts. I haven't made a staff panel for it, just because its super simple, haha. This mod contains some javascript too! :D Things to note: -An individual player may only rate a single post once! -A player cannot rate their own posts! The SQL: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. forums.php FIND: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. UNDERNEATH PASTE: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. FIND NEXT: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. UNDER THAT, PASTE: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. Now, outside of a function. Paste in: You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. Should work fine. I tested it against basic SQL injections. If you liked it, like my post or thank it. ^^ Screenies: [ATTACH]2158[/ATTACH] [ATTACH]2159[/ATTACH] Quote Link to comment Share on other sites More sharing options...
cmd Posted August 6, 2015 Share Posted August 6, 2015 You could perhaps rather than doing a conditional statement to check if a row already exists if the user has already rated the same, rather than doing that, nest your current conditional statements within a TRY/CATCH? then obviously make your table fields unique (post and user id) then just instantly try and insert? If the row already exists it will fall into the catch statement, thats when you display an error "you've already rated this post".. just a suggestion :} Quote Link to comment Share on other sites More sharing options...
Dayo Posted August 6, 2015 Share Posted August 6, 2015 (edited) A few points 1) Whats the need for the poster field as i cant see where it is used and in theory if you have the post id you can inner join the post to get the poster 2) You have the same query in three places (apart from the pating that could be a variable) you could do something like You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. 3) "You have successfully not rated this post!" < may cause confusion Edited August 6, 2015 by Dayo Quote Link to comment Share on other sites More sharing options...
cmd Posted August 6, 2015 Share Posted August 6, 2015 I agree Dayo, your tables could be much more normalized.. having a table for just posts then having a table for topics for example, suggesstions, question, general discussion etc.. then have another table for ratings, within the ratings you want to put the userID and the ratingID then have another table for ratings, given that id 1 within the ratings table is thanks and 2 is dislike and 3 is like.. quick example: Post(postID, ownerID*, post, subject, topicID*) Topics(topicID, topic) Ratings(ratingID, rating) post_ratings(ratingID*, postID*, userID*) user_posts(*postID, comments) Given that the bold parts are PK's and the asterisks are FK's etc.. just a suggestion to clean up your tables :) Quote Link to comment Share on other sites More sharing options...
Coly010 Posted August 6, 2015 Share Posted August 6, 2015 You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. I dunno, I just think this looks neater. Done on my phone. Quote Link to comment Share on other sites More sharing options...
cmd Posted August 6, 2015 Share Posted August 6, 2015 You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. I dunno, I just think this looks neater. Done on my phone. I'd say take a DB approach to storing ratings and so on rather than hardcoding stuff, that way it'd make the website a little more dynamic Quote Link to comment Share on other sites More sharing options...
Zephyr Posted August 6, 2015 Share Posted August 6, 2015 Good work [MENTION=70574]TheMasterGeneral[/MENTION] Whilst there are a few things that can be improved, I feel it's best If I spend less time on explaining how you can improve it, especially since everyone else is giving some very useful information. I will however thank you for your contribution, it's a good little add-on that makes the standard McCodes forum a bit better. So good work, keep it up, and have fun! Quote Link to comment Share on other sites More sharing options...
Coly010 Posted August 6, 2015 Share Posted August 6, 2015 I'd say take a DB approach to storing ratings and so on rather than hardcoding stuff, that way it'd make the website a little more dynamic Lol yeah trust me that went through my head but he said he didn't have a staff panel for it Quote Link to comment Share on other sites More sharing options...
~Rob0t Posted August 6, 2015 Share Posted August 6, 2015 Nice, but a couple things to improve on. You don't need 3 separate queries to get your stats, simply just do it all in one query - http://sqlfiddle.com/#!9/3df4b/1 You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. --------------- You don't need to query and bring every column back (ie: SELECT *...) it's a waste of overhead. Select what you need. --------------- You have an } else { to print a blank string. Weird logic... --------------- You're not ending the headers to make the screen look nice. $h->endpage(); --------------- Perhaps make use of a switch() statement, instead of multiple if/else blocks. You don't need to put your query inside each if(){} block in the rating snippet. Don't Repeat Yourself. Quote Link to comment Share on other sites More sharing options...
TheMasterGeneral Posted August 6, 2015 Author Share Posted August 6, 2015 1) Whats the need for the poster field My apologies! That was something else I added into the game. Its used to track how many thanks/likes/dislikes a player has received. You don't need 3 separate queries to get your stats Yeah. I see the error of my ways. I'm not a(n) 1337 PHP'er/MySQLi'er You're not ending the headers to make the screen look nice. $h->endpage(); From the POV of my WAMP server, $h->endpage(); was already called outside all the functions. You don't need to query and bring every column back Yeah. Quite stupid of me. Coding at midnight, like a freaking boss. >_> I'll clean it up a little bit! Stay tuned. ^^ Quote Link to comment Share on other sites More sharing options...
SecurityEh Posted August 12, 2015 Share Posted August 12, 2015 Just to point it out here, I "think" is a possible injection though due to me being slightly tired who knows. You're unable to view this code. Viewing code within this forum requires registration, you can register here for free. Just to give you a heads up. 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.