Hello. I have a counter that isn't incrementing. Thanks for having a quick look:

  1. Select the highest value from counter table, by subseason.
  2. If there is a value, increment it by one and assign it to $incremented_count.
$count_select1 = "
SELECT *
FROM ol_counter
WHERE olc_subseason_pk = '$subseason_pk'
ORDER BY olc_val DESC
LIMIT 1
";

$count_result1 = mysql_query($count_select1) 
			or die ("couldn't execute onloc increment query 1");

$count_row1 = mysql_fetch_array($count_result1);
$numrows1 = mysql_num_rows($count_result1);

$count = $count_row1["olc_val"];

if ($numrows1 > 0)

{	
$incremented_count = ($count++);
}

else

{		
}

thanks

knelson

    Actually, your code does cause $count to be incremented.

    The main problem would be that you want:
    1. Increment $count
    2. Assign $count to $incremented_count

    but your code is doing:
    1. Assign $count to $incremented_count
    2. Increment $count

    A solution would be to use ++$count instead of $count++
    or, use $count++, then $incremented_count = $count

    if you dont even plan to use $count later, then best is $incremented_count = $count + 1;

      thanks for helping to clear that up..

      i reverted to $count +1 just after I posted, and still had problems...until i removed the parens. bizarre. anyway, i'm following your advice and sticking with the "+ 1" scenario...it seems to be working fine now.

      thanks again and have a good one...

      knelson

        It isnt some sort of compound mathematical formula, so generally it is silly to place the parentheses in.

        Still, it's unusual that it doesnt work with the parentheses.

          Write a Reply...