Click to See Complete Forum and Search --> : (while if) structure.....not looping


beginnerz
08-30-2006, 02:40 AM
function getCheckBoxLinkUser(){
global $db;

$sql = "select * from usergroup order by rank ASC";
$query = $db->query($sql);
while($row = $query->FetchRow()){
$noSpace = str_replace(" ", "", $row['usergroup']);
if($_GET[''.$noSpace.''] == 'true'){
//echo $row['usergroup'].$last_id;
$insert = "insert into usergroup_info set user_id = 23, usergroup_id=".$row['pkey'];
echo $insert;
$query = $db->query($insert);
}
}
}

Why after i added $query = $db->query($insert); <--- this line, this function totally stop looping, if exclude this line, everything is going well. Anybody face this same problem before?
I m using php 5.1.4 and adodb classes for mysql function.

NogDog
08-30-2006, 07:19 AM
The $query inside of your IF block is overwriting the $query just above the WHILE statement. You need to use a different variable name for the second one.

beginnerz
08-30-2006, 09:10 AM
o yea, i just notice that, super thanks