0

This is essentially a rating system where some text is displayed, users click good/bad, and the database has a vote added or subtracted from it. I am currently trying to do it like this:

File #1 (rate.php) - prints random database row with text in. There is a 'good' hyperlink which goes to good.php and a 'bad' hyperlink which goes to bad.php.

File #2 (good.php or bad.php) - Clicking the links adds or removes a vote to/from the database as appropriate and returns to rate.php via the header function.

I am currently having difficulty passing the variable from the while loop to good.php and bad.php. Because they are hyperlinks, there is no form.

Should I even be using a while loop? Is there a better way to structure the whole thing? Does this call for sessions?

EDIT:

Here is the while loop.

$query = "SELECT * FROM challenges WHERE visible = 1 ORDER BY RAND() LIMIT 0,1";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
    echo "<div id='box'>";
    echo $row['challenge'];
    echo "</div>";
    echo "<div style='text-align: center; font-size: 12px;'>
<span id='good'><a href='good.php'>good</a></span> &nbsp;
<span id='skip'><a href='rate.php'>skip</a></span> &nbsp;
<span id='bad'><a href='bad.php'>bad</a></span></div>";
}
3

1 Answer 1

0

just pass a row ID with GET variable

good.php?row_id=12345
bad.php?row_id=12345

in good.php and bad.php it becomes a variable like:

$_GET['row_id']
2
  • 2
    @Sebastian - That's just bad practice.. you should really use POST instead. Make a button named good and one named bad. Wrap them in a form and then in your rate.php page add the code for when the user submits using the good button, and then using the bad button Commented Jul 21, 2012 at 19:40
  • i also recommend to POST this variable, but as long as @Sebastian want to do this via links, it's the easiest way Commented Jul 21, 2012 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.