Hello!
I have a problem with my vote script 🙂
Im using paging script that shows all rows in my DB in pages, but i want to make a link to vote script, but when I try to vote for some game, it vote for all games :\
Sorry for my bad English and I think that you understand me 🙂
Here is the paging script:
<?php
$rowsPerPage = 4;
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT * FROM games WHERE `cat` = 'action' LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die(mysql_error());
while($red = mysql_fetch_array($result)):
?>
» Name: <?php echo $red["name"]; ?><br>
<a href="vote.php">Vote for that game!</a>
<?php endwhile;
echo '</div>
<p><div style="position: absolute; top: 690px; left: -6px; width: 450px;"><p>';
$query = "SELECT COUNT(name) AS numrows FROM games WHERE `cat` = 'action' ";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?cat=action&page=$page\">[«]</a> ";
$first = " <a href=\"$self?cat=action&page=1\">[««]</a> ";
}
else
{
$prev = ' [«] ';
$first = ' [««] ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?cat=action&page=$page\">[»]</a> ";
$last = " <a href=\"$self?cat=action&maxPage\">[»»]</a> ";
}
else
{
$next = ' [»] ';
$last = ' [»»] ';
}
echo $first . $prev . " Page <strong>$pageNum</strong> от <strong>$maxPage</strong> " . $next . $last;
?>
And the voting script:
<?php
session_start();
include 'inc/db.php';
$query = "SELECT * FROM games";
$result = mysql_query($query) or die('Error, query failed');
while($red = mysql_fetch_array($result))
{
$id = $red['id'];
$vote = $red['rate'];
$i2 = $vote + 1;
$qs2 = mysql_query("UPDATE `games` SET `rate` = '$i2' where `id` = '$id'") or die(mysql_error());
}
?>
Main idea is when I click on 'Vote for that game!' to update only the row of that game.
I will be very happy if you write a basic script that shows me a way to do that thing...
10x
PS:
And sorry for my bad English again 🙂