RIRedinPA Posted April 21, 2009 Share Posted April 21, 2009 this is driving me nuts, I am trying to update my database before I display the results for the users, two of the fields I have are groupname and grouprank. If a user has created an item and not given it a groupname from the list of groupnames they have created I give it a groupname of unassigned. I then read back the highest grouprank, create a new one that is +1, and give all the unassigneds that new highest ranking, then display the data ordering by ASC grouprank. Problem is the update to change the unassigned grouprank is not working from PHP. Here's the code, with variable names: //get highest grouprank that is not an unassigned group $query = "SELECT grouprank FROM $tablename WHERE groupname <> 'Unassigned' OR groupname IS NULL ORDER BY grouprank DESC LIMIT 1"; $result = doQuery($query); $itemcount = mysql_num_rows($result); $i=0; if ($itemcount > 0) { while($itemcount > $i) { $i++; $grouprank = mysql_result($result, $i-1, 'grouprank'); if ($grouprank == 'NULL') { $grouprank = 0; } } } else { $grouprank = 0; } //make new highest rank $thisgrouprank = $grouprank + 1; //set unassigned to last group rank $uaquery = "UPDATE $tablename SET grouprank = $thisgrouprank WHERE groupname LIKE '%Unassigned%' OR groupname IS NULL"; $uaresult = mysql_query($uaquery) or die ("There was a problem updating the groupranks for unassigned groups"); $uaerror = mysql_error(); when I echo $usquery this is what I get: UPDATE AA_09012008 SET grouprank = 8 WHERE groupname LIKE '%Unassigned%' OR groupname IS NULL which is correct. If I place that command in my db admin tool it works fine, updates all the records correctly. I get no errors from mysql_error() and die is not echoing anything so I am assuming the query is reaching the db. But the fields are not being updated. What am I doing wrong here? Link to comment https://forums.phpfreaks.com/topic/155019-mysql-query-not-working-from-phpno-errors-variables-are-correct/ Share on other sites More sharing options...
revraz Posted April 21, 2009 Share Posted April 21, 2009 Is the grouprank data type set to INT? Link to comment https://forums.phpfreaks.com/topic/155019-mysql-query-not-working-from-phpno-errors-variables-are-correct/#findComment-815402 Share on other sites More sharing options...
RIRedinPA Posted April 21, 2009 Author Share Posted April 21, 2009 Is the grouprank data type set to INT? yes. Link to comment https://forums.phpfreaks.com/topic/155019-mysql-query-not-working-from-phpno-errors-variables-are-correct/#findComment-815413 Share on other sites More sharing options...
RIRedinPA Posted April 21, 2009 Author Share Posted April 21, 2009 Groan. Problem solved, programmer stupidity, I was resetting the groupranks further down in the code, eliminating the work I was doing further up... Link to comment https://forums.phpfreaks.com/topic/155019-mysql-query-not-working-from-phpno-errors-variables-are-correct/#findComment-815558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.