[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

4.6

Simple php poll problem

Asked by rabidlemming in PHP Scripting Language

Tags: from, php, rating

hi,

I have made a php poll based on the same php poll used to rate flash tutorials at flash kit. Example: http://www.flashkit.com/tutorials/Getting_Started/

Your notice how each tutorial has a number of hits and rating (number of votes) displayed near it name. When you open up the tutorial their is a voting system, that you can use to vote with.

Example:
http://www.flashkit.com/tutorials/Getting_Started/Using_La-Eddie_Ca-10/index.php

My php poll is exactly the same. My problem is that I don't want users to be able to vote more than once. The user needs to be able to vote once for each tutorial. I don’t want the user to be locked out from voting on all the tutorials once they vote for one of them. Quite simple a user can vote for a tutorial once only but can cast a vote on each tutorial at least once. The code needs to be simple as wee add new tutorials on a regular bases. I also haven't a clue how to use mysql so if your code uses that feature you need to explain it to me in layman’s terms please. If a user has already voted I want a message on the tutorial page where they cast their vote to be displayed saying sorry you have already voted. You will need to use and edit the code below.

You can see a working example of my poll here: http://www.webwasp.co.uk/test/poll/

The first tutorial : Simple Links  (http://www.webwasp.co.uk/test/poll/a01=simple-links/index.php) is the only one that has the php poll installed on it so far

Any help would be appreciated

This is all my code for the php poll:

Ratings.php
http://www.webwasp.co.uk/test/poll/Ratings.php
=====================================================================================
  <table border="1" cellspacing="0" cellpadding="0" align="center">
    <tr><td align="center">Please Indicate what you thought about this Tutorial</td></tr>
      <tr><td align="center">(1 for the worst review, 10 for the best...)</td></tr>
    <tr>
      <td align="center">
         <table width="100%" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center"><input type="checkbox" name="checkbox1" value="1" onClick="Javascript:HandleBoxes(1)">1</td>
            <td align="center"><input type="checkbox" name="checkbox2" value="2" onClick="Javascript:HandleBoxes(2)">2</td>
            <td align="center"><input type="checkbox" name="checkbox3" value="3" onClick="Javascript:HandleBoxes(3)">3</td>
            <td align="center"><input type="checkbox" name="checkbox4" value="4" onClick="Javascript:HandleBoxes(4)">4</td>
            <td align="center"><input type="checkbox" name="checkbox5" value="5" onClick="Javascript:HandleBoxes(5)">5</td>
                  <td align="center"><input type="checkbox" name="checkbox5" value="5" onClick="Javascript:HandleBoxes(6)">6</td>
                  <td align="center"><input type="checkbox" name="checkbox5" value="5" onClick="Javascript:HandleBoxes(7)">7</td>
                  <td align="center"><input type="checkbox" name="checkbox5" value="5" onClick="Javascript:HandleBoxes(8)">8</td>
                  <td align="center"><input type="checkbox" name="checkbox5" value="5" onClick="Javascript:HandleBoxes(9)">9</td>
                  <td align="center"><input type="checkbox" name="checkbox5" value="5" onClick="Javascript:HandleBoxes(10)">10</td>
          </tr>
        </table>
       </td>
    </tr>
    <tr><td align="center"><form action='<?php print (ReturnCurrPage($HTTP_SERVER_VARS['PHP_SELF'])); ?>' target="_self" method="post" name="Rating">
                             <input name="CurrentArticle" type="hidden" value="<?php print $ArticleID ?>">
                             <input name="SelectedRating" type="hidden" value="">
                             <input type="submit" name="Submit" value="Submit">
                                       </form>
    </td></tr>
  </table>
=====================================================================================



Rating_Functions.php:
http://www.webwasp.co.uk/test/poll/Rating_Functions.php
=====================================================================================
<?php
  function ReturnCurrPage($CurrPage){
      for ($x=0;$x<strlen($CurrPage);$x++) {
        if ($CurrPage[$x] == "/") { $tmpPos = $x; }
      }
      return (substr($CurrPage,($tmpPos+1)));
  }

  function UpdateRating() {
    $strError = "";
    $Flag = 3;
    $link = mysql_connect("*****","*****","*****") or $Flag = 1;
    if ($Flag == 3){
      mysql_select_db("webwasp_co_uk1") or $Flag = 2;
      if ($Flag  <> 3){
        mysql_close($link);  // No Database Found Found!
      } else {  // DB LINK ESTABLISHED
        $z = $_POST['CurrentArticle'];
        $query = "select NumofRates, CurrentScore  from ratings where ArticleID = '$z';";
        $result = mysql_query($query);
        if (mysql_num_rows($result) == 0) {
          // ERROR NO ARTICLE IN DB - START NEW ID RECORD
          $x = 1;
              $y = $_POST['SelectedRating'];
              $query = "Insert Into ratings Values ('$z', '$x' , '$y');";
          mysql_query ($query);
        } else {
          while ($row = mysql_fetch_row($result)) {
            $x = $row[0];
            $y = $row[1];
          }
          $x++;
          $y = $y + $_POST['SelectedRating'];
          $query = "Update ratings Set NumofRates = '$x', CurrentScore = '$y' Where ArticleID = '$z';";
          mysql_query($query);
        }
      }
      mysql_close($link);   // CLOSE DB
    } else { // NO CONNECTION AVAILABLE
      }
  }

  function ReturnRating($ArtID) {
    $strError = "";
    $Flag = 3;
    $link = mysql_connect("*****","*****","*****") or $Flag = 1;
      if ($Flag == 3){
      mysql_select_db("webwasp_co_uk1") or $Flag = 2;
        if ($Flag  <> 3){
        mysql_close($link);  // No Database Found Found!
        $ReturnVar =  "Not Rated";
        } else {  // DB LINK ESTABLISHED
        $z = $ArtID;
        $query = "select NumofRates, CurrentScore  from ratings where ArticleID = '$z';";
        $result = mysql_query($query);
        if (mysql_num_rows($result) == 0) {     //  NO ARTICLE IN DB - NOT RATED
          $ReturnVar =  "Not Rated";
        } else {
          while ($row = mysql_fetch_row($result)) {
            $x = $row[0];
            $y = $row[1];
          }
          $tmpVal = ($y / $x);
              if (strpos($tmpVal,".") === false){
                $tmpVal = $tmpVal . ".00";
              } else {
                if ( ((strlen($tmpVal)) - (strpos($tmpVal,"."))) > 3 ) {
                    $tmpWhole = substr($tmpVal, 0, strpos($tmpVal,"."));
                    $tmpDec = substr($tmpVal,strpos($tmpVal,".")+1);
                    for ($loop=(strlen($tmpDec));$loop>1;$loop--){
                        if (  $tmpDec[$loop] >= 5 ) {  ($tmpDec[$loop-1]) +1; }
                    }
                    $tmpDec = substr($tmpDec,0,2);
                    $tmpVal = $tmpWhole . "." . $tmpDec;
                  }
              }
              $ReturnVar = "Rated: " . $tmpVal . " / 10";
        }
        mysql_close($link);   // CLOSE DB
      }

    } else { // NO CONNECTION AVAILABLE
        $ReturnVar =  "Not Rated";
      }
      return ($ReturnVar);
  }
?>
=====================================================================================


Rating.js
http://www.webwasp.co.uk/test/poll/Rating.js
=====================================================================================
// JAVA SCRIPT RATING'S FORM HANDLER
function HandleBoxes(intBox){
  document.Rating.SelectedRating.value = intBox;
  checkbox1.checked = false;
  checkbox2.checked = false;
  checkbox3.checked = false;
  checkbox4.checked = false;
  checkbox5.checked = false;
  switch (intBox){
    case 1: checkbox1.checked = true;
            break;
    case 2: checkbox2.checked = true;
            break;
    case 3: checkbox3.checked = true;
            break;
    case 4: checkbox4.checked = true;
            break;
    case 5: checkbox5.checked = true;
            break;
  }
}
=====================================================================================


Index page for the tutorial where user can vote:
http://www.webwasp.co.uk/test/poll/a01=simple-links/index.php
=====================================================================================
<!-- RATINGS VARIABLES START   -->
//Sets the uniqe ID for the tutorial
//Each tutorial must have it's own ID
<?php
  $ArticleID = 1;  //CHANGE THIS VALUE TO INDICATE CURRENT DOCUMENT'S RATING TABLE ID
  include ("../Rating_Functions.php");
  if ( (isset($_POST['SelectedRating'])) && $_POST['SelectedRating'] != ""){ UpdateRating(); }
?>
<script language="JavaScript" type="text/javascript" src="../Rating.js"></script>
<!-- RATINGS VARIABLES END -->

//Displays the voting table
  <!-- RATINGS VARIABLES START   -->
<?php include ("../Ratings.php"); ?>
<!-- RATINGS VARIABLES END   -->
=====================================================================================


Index page for the list of all the available tutorials. Where the ratings are displayed for each tutorial
http://www.webwasp.co.uk/test/poll/index.php
=====================================================================================
<!-- RATINGS VARIABLES START   -->
<?php include ("Rating_Functions.php"); ?>
<!-- RATINGS VARIABLES END  -->


<?php print(ReturnRating(1)); ?>
=====================================================================================

Cheers
Rabid Lemming

 
 
[+][-]08/07/04 06:11 AM, ID: 11742549Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/07/04 04:36 PM, ID: 11744765Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/07/04 09:07 PM, ID: 11745228Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/07/04 11:06 PM, ID: 11745438Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/07/04 11:33 PM, ID: 11745488Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 12:22 AM, ID: 11745574Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 12:24 AM, ID: 11745578Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 12:31 AM, ID: 11745594Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 12:33 AM, ID: 11745601Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 12:40 AM, ID: 11745613Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 12:58 AM, ID: 11745651Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 01:10 AM, ID: 11745665Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 01:27 AM, ID: 11745690Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 01:31 AM, ID: 11745696Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 01:32 AM, ID: 11745700Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 01:55 AM, ID: 11745752Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 02:17 AM, ID: 11745780Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 02:19 AM, ID: 11745784Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 02:20 AM, ID: 11745785Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 02:40 AM, ID: 11745809Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 03:02 AM, ID: 11745838Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 03:07 AM, ID: 11745845Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP Scripting Language
Tags: from, php, rating
Sign Up Now!
Solution Provided By: zac_charles
Participating Experts: 2
Solution Grade: A
 
[+][-]08/08/04 03:25 AM, ID: 11745868Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/08/04 03:29 AM, ID: 11745875Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/08/04 03:31 AM, ID: 11745882Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89