Jump to content

MySQL query not working from PHP...no errors, variables are correct...


RIRedinPA

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.