Ver Mensaje Individual
  #18 (permalink)  
Antiguo 26/04/2008, 10:04
Avatar de nuckzuniga
nuckzuniga
 
Fecha de Ingreso: marzo-2008
Mensajes: 71
Antigüedad: 18 años, 7 meses
Puntos: 0
Re: While problematico

Tampoco me funciono. Esque, saben que es lo que me parece raro, que yo uso ese mismo bucle en otro modulo, donde uso el while para repetir la cantidad de filas mientras hayan proyectos en la base de datos, y me funciona de lo mejor. Sin embargo, al hacer lo mismo en este modulo, no me lo acepta.

Este es el codigo del modulo que funciona Bien:

Código PHP:
<?PHP

//...select mensaje, fecha, id_usuario
$sql_msg="SELECT mensajes.mensaje, mensajes.fecha, mensajes.id_usuario, mensajes.id FROM mensajes WHERE mensajes.id_proyecto='$id_proyecto' order by mensajes.fecha DESC";
//...Ejecuta Query
$res_msg = mysql_query($sql_msg,$dbh);


while (
$row_mensaje = mysql_fetch_array($res_msg, MYSQL_NUM)) 
{

$sql_user="SELECT usuario.nombre, usuario.cargo, usuario.id_empresa FROM usuario WHERE usuario.id='$row_mensaje[2]'";
$res_user = mysql_query($sql_user,$dbh);
$row_user=mysql_fetch_array($res_user,MYSQL_NUM);


//Consulta Empresa

$sql_empresa = "SELECT empresa.nombre FROM empresa WHERE '$row_user[2]'= empresa.id";
$res_empresa = mysql_query($sql_empresa,$dbh);
$row_empresa=mysql_fetch_array($res_empresa,MYSQL_NUM);

?>



<table width="550"border="0" class="texto"  style="margin-left:130px;">
 <tr>
    <td width="75%" height="10"> 
        <?    echo "<strong>";
            echo 
$row_user[0]; //nombre
            
echo "<br>".$row_user[1]; //cargo
            
echo "<br>".$row_empresa[0];//empresa
            
echo "</strong>";
            
        
?>    </td>
    <td width="25%" class="texto"><? echo "<div class='style17'>".$row_mensaje[1]."</div>"; //Fecha ?></td>
 </tr>
 <tr>
    <td height="10" colspan="4" >
    <span class="style17">
    <?    echo "<font color='#336699'><div align=justify>".$row_mensaje[0]."</div></font>";     //Mensaje ?>
    </span>        </td>
 </tr>
 <tr>
    <td height="39" colspan="4" class="texto">
<br>
<? 
$sql_muestradjuntos
="select nombre, adjuntos.ruta FROM adjuntos, mensajes WHERE adjuntos.id_mensaje = $row_mensaje[3]";
$res_muestradjuntos =mysql_query($sql_muestradjuntos,$dbh);    

    
$row_muestradjuntos = mysql_fetch_array($res_muestradjuntos,MYSQL_NUM);
    if(
$row_muestradjuntos[1]!="")
    {
    
$ruta = "$row_muestradjuntos[1]";
    echo 
"<font color='#FF0000'><strong>Adjunto: </strong></font><a href='$ruta'>.$row_muestradjuntos[0]</a>";
    }
?>    </td>
 </tr>
</table>



<div  style=" margin-left:130px; width:550px;">
<hr>
<hr>
</div>

<? } @mysql_free_result($result); ?>

Y este es el que no me funciona.

Querys:

Código PHP:
 <?PHP
$id_user
=$_SESSION["id_usuario"];

//id de los proyectos que tiene acceso
$sql_proyecto ="SELECT  a.id_proyecto, u.nombre, u.id, a.idusuario FROM acceso  AS a left join proyectos AS p ON a.id_proyecto = p.id left join empresa AS e ON e.id=p.id_empresa WHERE  a.id_usuario='$id_user'";
$res_proyecto = mysql_query($sql_proyecto,$dbh);
$row_proyecto = mysql_fetch_array($res_proyecto, MYSQL_NUM);

$sql_nombres = "SELECT a.nombre, u.nombre FROM adjunto a LEFT JOIN usuario u ";
$res_nombres =mysql_query($sql_nombres,$dbh);
while (
$row_nombres= mysql_fetch_array($res_nombres, MYSQL_NUM)) 

$sql_permisos = "SELECT mensajes.id FROM mensajes WHERE mensajes.id_proyecto = $row_proyecto[0]";
$res_permisos = mysql_query($sql_permisos,$dbh);
$row_permisos = mysql_fetch_array($res_permisos, MYSQL_NUM);

$sql_proyecto1 ="SELECT adjuntos.nombre, adjuntos.ruta, adjuntos.id FROM adjuntos WHERE adjuntos.id_mensaje = $row_permisos[0] ORDER BY id_usuario";
$res_proyecto1 = mysql_query($sql_proyecto1,$dbh);

$sql_usuario = "SELECT usuario.nombre FROM usuario, adjuntos WHERE usuario.id = adjuntos.id_usuario ORDER BY id_usuario";
$res_usuario = mysql_query($sql_usuario,$dbh);
$row_usuario = mysql_fetch_array($res_usuario, MYSQL_NUM);
?>

While:

Código PHP:
<?PHP      while ($row_proyecto = mysql_fetch_array($res_proyecto1, MYSQL_NUM)) 
{
?>

<table width="650" border="0" cellspacing="0" style="margin-left:128px">
  <tr>
    <td width="616">
     
      <div align="left" class="style19">
        
        <table width="559" border="1">
          
          
          
          <tr>
            <th width="355" scope="col"><span class="style11">
              <?
    $ruta_uno 
= "./adjuntos/$row_proyecto[0]";
    echo 
"<strong><a href='$ruta_uno'>".$row_proyecto[0]."</a></strong>";
    
    

?>
            </span></th>
            <th width="188" scope="col"><span class="style11">
              <?PHP

    
echo "<strong>".$row_usuario[0]."</a></strong>";
    
?>
            </span></th>
          </tr>
          
        </table>
    </div>
    <div align="left"></div>
    <div align="left"></div><div align="left"></div></td>
  </tr>
</table>

<?PHP
} // fin del while

Que se les ocurre?