Dada78 Posted February 9, 2008 Author Share Posted February 9, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-462904 Share on other sites More sharing options...
laffin Posted February 9, 2008 Share Posted February 9, 2008 Never used a tutorial, but persistant in coming up with solutions. coding is experimentation. Tutorials show ya one way of doing somethings. but ya should always have the basics down, so ya can experiment. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-462917 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 That helps me how? Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-462938 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 The id isn't being assigned to the link mouse over and you will see it is not there. You click on one of the links to vote and you get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 <?php // MAKE CONNECTION include ('db_connect.php'); if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM users WHERE id = $id;"; if ($result = mysql_query($sql)) { if (mysql_fetch_assoc($result)) { $votes = $row['votes']; $total = $row['total']; } else { die("No user found"); } } else { die(mysql_error()); } } //We only run this code if the user has just clicked a voting link if (isset($_GET['mode']) && $_GET['mode']=="vote") { //If the user has already voted on the particular thing, we do not allow them to vote again $cookie = "Mysite$id"; if(isset($_COOKIE[$cookie])) { Echo "Sorry You have already ranked that site <p>"; } //Otherwise, we set a cooking telling us they have now voted else { $month = 2592000 + time(); setcookie(Mysite.$id, Voted, $month); //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 mysql_query ("UPDATE users SET total = total+$voted, votes = votes+1 WHERE id = $id"); Echo "Your vote has been cast <p>"; } } //This calculates the sites ranking and then outputs it - rounded to 1 decimal if (!$rating['votes'] || !$rating['total']){ $current = 0; echo "Unrated"; } else { $current = $ratings['total'] / $ratings['votes']; echo "Rated " . round($current, 1). " from $votes people"; } echo " | <b>Rate This Display</b>: "; //This creates 5 links to vote a 1, 2, 3, 4, or 5 rating for each particular item Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&id=".$ratings[id].">1</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=2&id=".$ratings[id].">2</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=3&id=".$ratings[id].">3</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=4&id=".$ratings[id].">4</a> | "; Echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=5&id=".$ratings[id].">5</a><p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463266 Share on other sites More sharing options...
trq Posted February 10, 2008 Share Posted February 10, 2008 I see a few issues. Here... $votes = $row['votes']; You use an array called $row which is not defined anywhere. Most likely, you want to define it using the result from mysql_fetch_assoc(). Further down your script you start using another undefined array. $ratings[], where does this come from? You should really put this... <?php ini_set('display_errors','1') ; error_reporting(E_ALL) ; ?> at the top of all your scripts (at least while devloping), this way you actually see all your errors. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463270 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 You use an array called $row which is not defined anywhere. I don't know what you mean by defined but it is use to show the results in the echo here echo "Rated " . round($current, 1). " from $votes people"; I am using this tutorial below as the guide so any questions as to why I am using what and where is because of this tutorial. http://php.about.com/od/finishedphp1/ss/rating_script.htm I have very little php experience and don't use it often and really don't have the time to sit down and learn it. Just need to get this down and learn enough to do what I need to do. Here can view the errors from the error reporting on this page http://www.mesquitechristmas.com/local/display.php?id=81 -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463328 Share on other sites More sharing options...
trq Posted February 10, 2008 Share Posted February 10, 2008 I have very little php experience and don't use it often and really don't have the time to sit down and learn it. Just need to get this down and learn enough to do what I need to do. Simply put, I don't really have time to sort through all your code and fix all your errors either. As I stated, you use two variables $row and $ratings in your code. Both of which are not defined anywhere. The code you posted in your last post has absolutely nothing to do with anything I've said. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463330 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 Man how rude, I wasn't specifically asking YOU to sort through all my code. I was just giving you some background information. The guy that was suppose to do the php didn't have time to do it after all. I don't have the money to pay someone even though I have someone but trying to get as much of it done myself so I won't have to spend as much. Like I have said already $votes = $row['votes']; is defined in the code if you read my last post you would see where it is used. As far as $ratings goes my last post explains that I am going by a tutorial and that is where that came from. Instead of quoting me and being a prick you could be a little more helpful since this is a support/help forum which you have not done ether. If you don't have time for me then please don't respond to my thread taking the focus away from my problem where maybe someone else can help me. -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463446 Share on other sites More sharing options...
trq Posted February 10, 2008 Share Posted February 10, 2008 This line.... $votes = $row['votes'] defines $votes. However, nowhere in your code is $row defined. I told you in my original reply how I assume you should define it. most likely, you want to define it using the result from mysql_fetch_assoc(). Hence your code should be.... <?php if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM users WHERE id = $id;"; if ($result = mysql_query($sql)) { if ($row = mysql_fetch_assoc($result)) { // <-- here $row is now defined. $votes = $row['votes']; $total = $row['total']; } else { die("No user found"); } } else { die(mysql_error()); } } As for the rest of your undefined variables. I can't help. You simply have variables appearing from nowhere. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463452 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 I can see you can't read. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463488 Share on other sites More sharing options...
Kingy Posted February 10, 2008 Share Posted February 10, 2008 dada what thorpe is trying to say is that $row needs to be defined before you define $votes. in the code that thorpe gave u just before if ($row = mysql_fetch_assoc($result)) { // <-- here $row is now defined. he defined $row for you so now $votes = $row['votes']; will be correctly defined and will work properly.. In php when using variables they have to be defined first. Eg: I have $apples apples. will not work because apples isn't defined. $apples = 3; I have $apples apples .. Explains itself Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463498 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 he id isn't being assigned to the link mouse over and you will see it is not there. You click on one of the links to vote and you get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463509 Share on other sites More sharing options...
trq Posted February 10, 2008 Share Posted February 10, 2008 I can see you can't read. What? Read my answers. Ive pointed out your issues several times as simply as I can. What do you want from me? he id isn't being assigned to the link mouse over and you will see it is not there. Because as Ive said. $ratings is not defined anywhere in your code! If your not going to read the answers provided, why bother asking questions? And having digs at me because you don't understand the answers is pretty well unhelpfull. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463511 Share on other sites More sharing options...
Kingy Posted February 10, 2008 Share Posted February 10, 2008 if (!$rating['votes'] || !$rating['total']){ $current = 0; echo "Unrated"; } else { $current = $ratings['total'] / $ratings['votes']; echo "Rated " . round($current, 1). " from $votes people"; } the id isn't showing because none of the above code is assigned. Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463514 Share on other sites More sharing options...
Dada78 Posted February 10, 2008 Author Share Posted February 10, 2008 What do you want from me? For you not to reply anymore. Because as Ive said. $ratings is not defined anywhere in your code! No shit really? I think I have already stated this problem. the id isn't showing because none of the above code is assigned. Really? You came to that conclusion on your own? I think I know this already and I think I have already stated my issue. I posted here for help with this not for people to point out the obvious. Geez.... Is their anyone out there who can suggest how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463527 Share on other sites More sharing options...
Kingy Posted February 11, 2008 Share Posted February 11, 2008 well i suggest you do a mysql query to select the information for votes and total, so you can work out the correct rating, and then u can get the id showing as well so when they rate it it will work properly Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463554 Share on other sites More sharing options...
Dada78 Posted February 11, 2008 Author Share Posted February 11, 2008 nevermind I give up.... Quote Link to comment https://forums.phpfreaks.com/topic/90065-rating-script-help/page/2/#findComment-463565 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.