Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/04/2011, 06:53
oscarbt
 
Fecha de Ingreso: abril-2009
Ubicación: Colombia
Mensajes: 949
Antigüedad: 15 años
Puntos: 27
Omitir datos repetidos en un while

Buenas a todos los foreros, me gustaria saber como puedo omitir valores repetidos dentro de un while, (teniendo que dejar el codigo dentro del ciclo)

Os explico.....resulta q yo tengo un modulo principal y dentro de ese modulo hay submodulos, los cuales a su vez tienen procesos

Entonces el ideal es mostrar la informacion asi:

MODULO PRINCIPAL 01

Submodulo 01
Proceso 0101
Proceso 0102

Submodulo 02
Proceso 0201
Proceso 0202

Lo que realmente no he podido hacer, ya que la informacion la muestro asi:

MODULO PRINCIPAL 01

Submodulo 01
Proceso 0101
Submodulo 01
Proceso 0102

Submodulo 02
Proceso 0201
Submodulo 02
Proceso 0202

Es decir, debo mostrar solo una vez la palabra Submodulo
Como lohago?

Aca el codigo :

Código PHP:
Ver original
  1. <?php
  2. $obj = new Conectar($myServer, $myUser, $myPass, $myDB);
  3.     $sql="SELECT B.MODCODIGO, MODNOMBRE, A.CODPROCES, B.NOMPROCES, A.PARAMCODIGO,PARAMNOMCOR,PARAMNOMLAR,NIVEL
  4. FROM GEPARAMSW A INNER JOIN SWPROCES B ON A.CODPROCES = B.CODPROCES INNER JOIN SWMODULO C ON C.MODCODIGO = B.MODCODIGO  
  5.     INNER JOIN SWPARAMPER D ON D.CODPROCES = A.CODPROCES AND A.PARAMCODIGO = D.PARAMCODIGO
  6. WHERE PERCODIGO = '".$cod."' ORDER BY MODNOMBRE";
  7.    $obj->consulta($sql);
  8. $field = $obj->numCampos();
  9. $numfilas = $obj->numFilas();
  10. $registros[0][0]="";
  11. $i=0;
  12. while($row = sqlsrv_fetch_array($obj->result)){
  13.     $j=0;
  14.     while($j<$field)
  15.     {
  16.     $registros[$i][$j]=$row[$j];
  17.     $j++;
  18.     }
  19.     $i++;
  20. }
  21. $i=0;
  22. $mod = "";
  23.  
  24. while($i<$numfilas)
  25. {
  26.  if($mod!=$registros[$i][0])    {
  27.  
  28.  echo "<tr><td align='right' valign='top' width='226' height='18'><font style='font-size:13px' color='#3426D9' face='Arial'><b>MODULO DE ".$registros[$i][1]."</b></font></td>";
  29.  
  30. }
  31. //Aca es donde debo hacer lo que quiero
  32.  
  33. if($mod!=$registros[$i][2]) {
  34.  
  35. echo "<tr><td align='right' valign='top' width='226' height='18'><font style='font-size:13px' color='#3426D9' face='Arial'><b>Proceso de ".utf8_encode($registros[$i][3])."</b></font></td>";
  36.  
  37.                                        }
  38.  
  39. echo "<tr  id='rolover'>";
  40. echo "<td align='center' valign='top' width='226' height='18'><font style='font-size:11px' color='#000000' face='Arial'>".utf8_encode($registros[$i][3])."</font></td>";
  41.  
  42. echo "<td align='center' valign='top' width='100' height='18'>".utf8_encode($registros[$i][5])."</td>";
  43.  
  44. echo "<td align='center' valign='top' width='100' height='18'>".utf8_encode($registros[$i][6])."</td>";
  45.  
  46. echo "<td align='center' valign='top' width='50' height='18'>".utf8_encode($registros[$i][7])."</td>";
  47.  
  48. echo "</tr>";
  49.  
  50. }//cierro el while
  51.  
  52. ?>

Agradezco me puedan indicar o guiar a traves de un ejemplo....gracias