Aquí está el código completo. Al imprimir las dos consultas, veo que son exactamente iguales. Pero la única que funciona es a la que se le pasa la constante 5.
   Código PHP:
    <?php
 
$grupo = "<script> document.write(perfil) </script>";
//echo "GRUPO = $grupo<br>";
 
echo '
<table border=1>
    <tr>
        <th>B/D</th>
        <th>TP</th>
        <th>Petición</th>
        <th>F. Aviso</th>
        <th>Centro</th>
        <th>Asunto</th>
        <th>Asignación</th>
        <th>Usuario</th>
        <th>F. Prevista</th>
        <th>P</th>
        <th>A/F</th>
     </tr>';
 
     $q = "select * from t_peticiones LEFT JOIN t_t_peticion on id_tipopeticion = id_t_peticion where id_perfil = 5 order by f_alta desc";
      $q1 = "select * from t_peticiones LEFT JOIN t_t_peticion on id_tipopeticion = id_t_peticion where id_perfil = $grupo order by f_alta desc";
 
     echo "Consulta1: $q<br>Consulta2: $q1<br>";
 
     $resq = mysql_query($q);
     
     while($rowq = mysql_fetch_array($resq)){
         
        if($rowq['id_usuario'] != ""){
        
            $qusu = "select nom_usuario from t_usuarios where id_usuario = ".$rowq['id_usuario'];
            
            $resqusu = mysql_query($qusu);
            $rowqusu = mysql_fetch_array($resqusu);
            $idusuario = $rowqusu['nom_usuario'];
        }    
        else{
            
            $idusuario = "-------";
        }    
                
        $qg = "select n_perfil from t_perfiles where id_perfil = 5";
        
        $resqg = mysql_query($qg);
        $rowqg = mysql_fetch_array($resqg);
        
        $estado = "select nom_estado from t_estado_pet where id_estado = ".$rowq['id_estado'];    
 
        $resestado = mysql_query($estado);
        $rowestado = mysql_fetch_array($resestado);
            
        if($rowestado['nom_estado']== "FINALIZADO")
            $est = "./images/ico/Finalizada.png";
        else{ 
            if($rowestado['nom_estado']!="PDTE. ACEPTACIÓN")    
                $est = "./images/ico/Abierta.png";
        }        
 
         echo '<tr>
                <td>';
                       
                       if($rowq['bloqueado'] != 1) 
                        echo '<img src="./images/ico/2BotonBloqOff.png"/></td>';
                    else 
                        echo '<img src="./images/ico/2BotonDesbloqOff.png"/></td>';
        echo'            
               <td>'.$rowq['cod_t_peticion'].'</td>
               <td><a href="javascript:ventanaSecundaria3(\'inf_det_peticion.php?peti='.$rowq['id_peticion'].'\')">'.$rowq["id_peticion"].'</a></td>
               <td>'.substr($rowq["f_alta"],0,10).'</td>
               <td>¿Centro?</td>
               <td align="center"><a href="javascript:ventanaDetalle(\'det_peticion.php?i='.$rowq['id_peticion'].'\')")><img src="./images/ico/2info.png" border=0/></a>  '.str_replace("+"," ", substr($rowq["asunto"],0,15)).'...</td>
               <td>'.$rowqg['n_perfil'].'</td>
               <td>'.$idusuario.'</td>
               <td>'.substr($rowq["f_limite"],0,10).'</td>
               <td>'.$rowq["id_prioridad"].'</td>
               <td><img src="'.$est.'"></td>
               </tr>';
    }
    
echo '</table>';
 
echo '<br><br>';
 
?>