I have the following problem. I 'm trying to automatically update the records of a database by refreshing a page.But updating the records isn't that simple in my case because some calculations & algoriths are needed before.
Anyway I'm updating the records with a do-while loop (I don't know if that's the best way to do it. If it isn't please, enlight me). I do that with a do-while loop as i said, by increasing the id (of the user ofc) by 1 each time. For example it updates records for user with id 1, then it updates records for user with id 2 etc till it reaches a limit.
In the do-while statement though I include a while statement because I want to extract some data from the excisting records in the database. With this data I'm doing the required calculations for the update. I told ya, it is quite complicated.
Here's the code (it's just a test, not the actual update):
Code: Select all
<?php
@$num = 1;
$name = "Alex";
do
{
$num++;
echo @$num. "<br>";
require("connect.php");
$extract = mysql_query("SELECT * FROM users WHERE id='$num'") or die("Couldn't dind user.");
$numrows = mysql_num_rows($extract);
while ($row = mysql_fetch_assoc($extract))
{
$id = $row['id'];
$name = $row['name'];
$username = $row['username'];
$password = $row['password'];
$email = $row['email'];
$points = $row['points'];
$date = $row['date'];
$slot1 = $row['slot1'];
$slot2 = $row['slot2'];
$slot3 = $row['slot3'];
$slot4 = $row['slot4'];
$slot5 = $row['slot5'];
$slot6 = $row['slot6'];
$slot7 = $row['slot7'];
$slot8 = $row['slot8'];
$slot9 = $row['slot9'];
$slot10 = $row['slot10'];
$bag1 = $row['bag1'];
$bag2 = $row['bag2'];
$bag3 = $row['bag3'];
$bag4 = $row['bag4'];
$bag5 = $row['bag5'];
$bag6 = $row['bag6'];
$bag7 = $row['bag7'];
$bag8 = $row['bag8'];
$bag9 = $row['bag9'];
$bag10 = $row['bag10'];
}
echo "user id: " .$id. " has a number of " .$points. " points";
if (@$num>=8)
$name = "billy";
}
while ($name == "Alex");
?>2
user id: 2 has a number of 90 points
Instead of getting
1
2
3
4
5
6
7
8
user id: 1 has a number of 100 points
user id: 2 has a number of 90 points
user id: 3 has a number of 85 points
user id: 4 has a number of 64 points
user id: 5 has a number of 72 points
user id: 6 has a number of 50 points
user id: 7 has a number of 100 points
user id: 8 has a number of 96 points
as I have 8 users.
But User 2 has 90 points so the values are correct.
Thanks in advnace.