>I have a function that resets the count of fields with certain values when
>called. 99.9 percent of the time it works fine. However occaisionally it
>wont update the database. Even after breaking the selects up it still fails
>sometimes. If anyone has an idea of why I would really appreciate hearing
>it. The code is below.

Are there other people/pages/process that are altering the 'active' state of
categories?

Because it's entirely possible that while the script below is only HALF
finished, somebody else comes in and alters the data out from under you.

Which means that your results will "seem" to be incorrect, since the state
of the world changed mid-stream.

You may want to use:

mysql_db_query($db, $query) or error_log(mysql_error());

instead of all those lines you have to comment/uncomment all the time.

When things go wrong, it will be in your Apache error_log

You may also be getting confusing results if some records has Category1 =
'foo' and Category2 = 'foo'  It's going to get "double-counted" in the
current algorithm.

If it's none of the above, you'll *have* to do some digging to figure out
what causes the 0.1% of the time...

>Thanks,
>Julian
>
><?
>//the selects had to be broken up to get it to work consistently
>function resetCounter()
>{
>include("../config.php");
>
>$query = "select categories from categories";
>$result = mysql_db_query($db, $query);
>while($r = mysql_fetch_array($result))
>{
>
>    $cats = $r["categories"];
>   // $active = $r["active"];
>   // echo"$cats<BR>";
>
>    $query1 = "select count(*) from recipes where category1 = '$cats' and
>active = 'yes'";
>   //  echo mysql_errno().": ".mysql_error()."  1<BR>"; // uncomment to
>troubleshoot db problems
>    $result2 = mysql_db_query($db, $query1);
>    $rows1 = mysql_fetch_row($result2);
>    $query2 = "select count(*) from recipes where category2 = '$cats' and
>active = 'yes'";
>   // echo mysql_errno().": ".mysql_error()."  1<BR>"; // uncomment to
>troubleshoot db problems
>    $result3 = mysql_db_query($db, $query2);
>    //echo mysql_errno().": ".mysql_error()."  2<BR>"; // uncomment to
>troubleshoot db problems
>    $rows2 = mysql_fetch_row($result3);
>    $query3 = "select count(*) from recipes where category3 = '$cats' and
>active = 'yes'";
>   // echo mysql_errno().": ".mysql_error()."  1<BR>"; // uncomment to
>troubleshoot db problems
>    $result4 = mysql_db_query($db, $query3);
>   // echo mysql_errno().": ".mysql_error()."  2<BR>"; // uncomment to
>troubleshoot db problems
>    $rows3 = mysql_fetch_row($result4);
>
>  // echo mysql_errno().": ".mysql_error()."  3<BR>"; // uncomment to
>troubleshoot db problems
>   $therows = $rows1[0] + $rows2[0] + $rows3[0];
>   $query4 = "UPDATE categories SET count = '$therows' where(categories =
>'$cats')";
>   $result5 = mysql_db_query($db, $query4);
>  // echo"$therows <--tr $rows1[0] <--r1 $rows2[0] <--r2 $rows3[0] <--r3
>$cats <-- cats<br>";
>
>}
>}
>
>?>
>
>
>
>
>


-- 
Like Music?  http://l-i-e.com/artists.htm


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to