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.
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>"; } } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php