Jump to content

updating table with $rank++


herman19

Recommended Posts

<?

$result = mysql_query("SELECT * FROM mclinkscounter ORDER BY clic DESC");

$rank = 1;

echo "<table border=\"0\"><tr><td>Game Name</td><td>Description</td><td>Hits</td><td>Rank</td></tr>";

while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['nom'] . "</td><td>" . $row['cat'] . "</td><td>" . $row['clic'] . "</td><td>" . $rank . "</td></tr>";
$rank++;
}
echo "</table>";
?>

This results in [a href=\"http://www.game-kings.com/php/test.php\" target=\"_blank\"]http://www.game-kings.com/php/test.php[/a]

Now, the first 3 values (nom, cat & clic) are taken from the database, the 'rank' value isn't, but I'm looking for something that updates the rank row in my database to the rank this code produces for that game.

Example: Bow man has rank 1 on this page, so I need something that sets rank = 1 for bow man, goldminer has rank 2 on this page, so I need something that sets rank = 2 for gold miner... etc.

I know how I can let the code run automatically, I just don't know the code yet :p
Link to comment
Share on other sites

Youre looking to update table ??
[code]
$id = "1"; // row id or similar
$clik = "2";

$update = mysql_query("update mclinkscounter set clik = '$clic' where id = '$id'") or die(mysql_error());

// or add up (+)
$update = mysql_query("update mclinkscounter set clik = clik + '$clic' where id = '$id'") or die(mysql_error());
[/code]
Link to comment
Share on other sites

nah, I don't want to change anything about the clic and id and cat rows... they're all good.

the only thing I want to update is the rank field

EDIT: below is the working code

<?
$result = mysql_query("SELECT * FROM table ORDER BY clic DESC");

$rank = 1;

echo "<table border=\"0\"><tr><td>Game Name</td><td>Category</td><td>Hits</td><td>Rank</td></tr>";

while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['nom'] . "</td><td>" . $row['cat'] . "</td><td>" . $row['clic'] . "</td><td>" . $rank . "</td></tr>";


mysql_query("update `table` SET `rank` = '". $rank ."' WHERE `id` = '". $row['id'] ."'") or die (Mysql_Error());

$rank++;
}
echo "</table>";
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.