perro88 Posted December 24, 2007 Share Posted December 24, 2007 I was thinking of making a rate system on my site. I already made something like this on a asp site so I need some help to translate this code. Then I'll try to add it First I made a vote.php file like this one vote.php if(user is NOT logged) show a message saying he is not logged so he can't vote or just redirect the guest to login page ID = parseInt(Request("ID")); // ID= ID of a topic that will have a rate system sql="SELECT *FROM Votes WHERE User='" + Username ID logged + "' AND ID=" + ID; /* Will create a table Votes on the database that will have a Vote_ID auto incremented, ID(from the topic to be voted), User(ID from the user who made the vote, an vote( a 0 to 10 integer)*/ rs_aux3=novors(sql); /*this thing was a recordset of the sql query, dunno how to make something like this on php*/ if(!rs_aux3.EOF) { write "You already voted on this topic before" and a link to the topic ex" <a href=\"index.php?topic=" + ID + "\">Back to topic</a>"); rs_aux3.Close(); rs_aux3 = null; } else { vote = String(Request.Form("vote")); sql = "INSERT INTO Votes (User,ID,vote) VALUES ('" + Logged User ID + "', '" + ID + "','" + vote + "')"; execsql(sql); /* execute the query*/ sql="SELECT COUNT(*) AS n_votes FROM Votes WHERE ID=" + ID; rs_aux=novors(sql); sql="SELECT AVG(vote) AS average FROM Votes WHERE ID=" + ID; rs_aux2=novors(sql); op=Math.round(rs_aux2.Fields.Item("average").Value*100)/100; /* I believe I made this bcause something related with the decimal part of the average */ sql="UPDATE topic_rating SET n_votes="+ rs_aux.Fields.Item("n_votos").Value + ", average=" + op + " WHERE ID=" + ID; /* Will create a table topic_rating on the DB with fields ID(topic ID) as key of the table and a n_votes(number of votes) and average(rate of the topic)*/ execsql(sql); /execute update query*/ write " Voted inserted " <a href=\"index.php?topic=" + ID + "\">Back to topic</a>"); rs_aux.Close(); rs_aux = null; rs_aux2.Close(); rs_aux2 = null; rs_aux3.Close(); rs_aux3 = null; } I need help to translate this and maybe a suggestion to create for example two tables like these(maybe a query through phpmyadmin): 1)name:votes .tablesvote_ID(key),ID(of the topic to be rated),user_ID(the id of the member who voted), vote(integer from 0 to 10) 2)name:topic_rating .tables(ID(ID of the topic)(key),N-Votes(number of votes of the topic),average(rating of the topic)) I also need help on some database vars calling: 1) call for example the fields N_Votes and Average of the current topic to 2 variables 2) The vote form should be something like this?: <form method="POST" action="vote.asp?ID= Current topic ID <select size="1" name="vote"> for(&i=1;&i<=10;&i++) echo'<option value=\"', &i , '\">', &i, '</option>'; </select> <input type="submit" value="OK" name="OK"></p> </form> thanks Link to comment https://forums.phpfreaks.com/topic/83081-need-help-to-translate-this-code/ Share on other sites More sharing options...
perro88 Posted December 25, 2007 Author Share Posted December 25, 2007 bump Link to comment https://forums.phpfreaks.com/topic/83081-need-help-to-translate-this-code/#findComment-422985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.