简体   繁体   中英

Passing PHP variable in loop to another PHP file via hyperlink

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>";
}

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM