Page 1 of 1

Problem with either my while loop or my syntax. [Solved]

Posted: Wed Jun 04, 2008 11:40 am
by nightswore
So I have a table of data that reads : Name | Date | Count. And what I'm trying to do is that every time a name comes up, I increase it's count by 1 and increase all other occurrences of the name's count by 1. So say Joe comes up, I want every instance of Joe to have its count increased by 1 so that no matter where I come across his name on the list, I know that Joe is on there X amount of times. To do this I employ this little while loop:

Code: Select all

while($rows = mysql_fetch_array($search))
{
    echo $rows['date'] . " " . $rows['name']. " " . $rows['count'];
      $increment = $rows['count'];
      $increment = $increment +1;
      $names = $rows['name'];
 
mysql_query("UPDATE temp SET count = '$increment' WHERE
name ='$names'");
 
}
The echo is really just for testing purposes as this page redirects at the bottom after it is finished working. The while loop takes the number that is currently in the count for the name and then increases it by 1 and then updates the count on the database.

Is there a problem with my update that it is only affecting the current instance of each name? Right now when I print out the table after implementing this loop each count is only at 1.

If someone can find an obvious flaw in this I would appreciate it because I've been staring at it for a while now and I'm starting to see it on the backs of my eyelids.

Thanks. -Z

Re: Problem with either my while loop or my syntax.

Posted: Wed Jun 04, 2008 12:48 pm
by RobertGonzalez

Code: Select all

<?php
while ($row = mysql_fetch_array($search)) {
  mysql_query("UPDATE `temp` SET `count` = `count` + 1 WHERE name ='$row[name]'"); 
}
?>

Re: Problem with either my while loop or my syntax.

Posted: Wed Jun 04, 2008 1:18 pm
by nightswore
A godsend you are, thanks!

-Z