Foros del Web » Programando para Internet » Javascript »

Recibir Variable desde PHP

Estas en el tema de Recibir Variable desde PHP en el foro de Javascript en Foros del Web. Hola Compañeros, tengo un problema que ya tengo varios intentando resolver pero no he podido,voy al grano: Tengo un formulario con un select, donde se ...
  #1 (permalink)  
Antiguo 22/09/2011, 14:48
 
Fecha de Ingreso: enero-2011
Ubicación: Maracaibo
Mensajes: 179
Antigüedad: 13 años, 3 meses
Puntos: 2
Recibir Variable desde PHP

Hola Compañeros, tengo un problema que ya tengo varios intentando resolver pero no he podido,voy al grano:

Tengo un formulario con un select, donde se despliegan ciertas empresas al seleccionar una empresa se ejecuta un codigo AJAX que me carga automaticamente una tabla, esta tabla me da cierto datos entre esos uno de descripcion, este dato es un campo BLOB en la base de datos, ya que las descripciones pueden ser muy largas, mi idea es limitar los caracteres a mostar dentro de esa tabla y colocar al final puntos suspensivos que al hacer click me levante una venta con la descripcion completa. aqui le dejo mis 2 codigos

Primero:

Código PHP:
<?php
session_start
();
if(!isset(
$_SESSION['us_id'])){
header("Location: ../index.php"); 
} else {
$usuario=$_SESSION['us_id'];
$admin=$_SESSION['us_tipo'];

include_once(
"conexion.php");
include(
'./Scripts/funcion.php');

$conexion = new ControlBD();
$conexion->conectar();
$conexion->seleccionarBD();
$query1="select * from cgusuarios where us_id='$usuario'";
$result1=$conexion->ejecutarQuery($query1);
$array1=mysql_fetch_array($result1);
$em_id=$array1['us_idempresa'];

$query2="select * from cgempresa";
$result2=$conexion->ejecutarQuery($query2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<script type="text/javascript" src="./Scripts/imprimir.js"></script>
<script type="text/javascript" src="./Scripts/jquery-1.6.1.js"></script>
<script type="text/javascript" src="./Scripts/tooltips.js"></script>
<script type="text/javascript" src="accion.js"></script>
<script type="text/javascript" src="./Scripts/jquery.uniform.js"charset="utf-8"></script>
<link rel=stylesheet href="./Style/uniform.default.css" type="text/css"> 
<link rel=stylesheet href="./Style/default.css" type="text/css">
<link rel=stylesheet href="./Style/menuH.css" type="text/css">

</head>
<script type="text/javascript">
 $(function(){
        $("input, textarea, select, button").uniform();
      });
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","req_selecionado.php?q="+str,true);
xmlhttp.send();
}
function mostrarVentana(id)
{
    var ventana = document.getElementById('miVentana'); // Accedemos al contenedor
    ventana.style.marginTop = "100px"; // Definimos su posición vertical. La ponemos fija para simplificar el código
    ventana.style.marginLeft = ((document.body.clientWidth-350) / 2) +  "px"; // Definimos su posición horizontal
    ventana.style.display = 'block'; // Y lo hacemos visible
        
}

function ocultarVentana(id)
{
    var ventana = document.getElementById('miVentana'); // Accedemos al contenedor
    ventana.style.display = 'none'; // Y lo hacemos invisible
}
</script>
</head>
<body>
<?php
    
include('menu.php');
?>
<form>
<div class="centrado">
<table width="342" height="156" class="backgroundRequerimiento" id="tablas">
<tr>
<? if($admin>=3){ ?>
    <th height="149"><br>
      &nbsp;&nbsp;&nbsp;&nbsp;Empresa/Proyecto</th>
    <td><br><select name="empresa" id="empresa" onchange="showUser(this.value)">
        <option value="0">--- Seleccione ---</option>
<?        while($array2=mysql_fetch_array($result2)) {?>
        <option value="<?=$array2['em_id']; ?>"><?=$array2['em_nombre']; ?></option>
        <? ?></select></td>
<? }if($admin==2){ ?>
    <td><input type="hidden" value="<?=$em_id;?>" name="empresa" /></td>
<? ?>
    <!--<th>Buscar por Estatus:</th>
    <td><select name="users" onchange="showUser(this.value, empresa.value)">
        <option value="">---Seleccione---</option>
        <option value="Pendiente">Pendiente</option>
        <option value="En Proceso">En Proceso</option>
        <option value="Terminado">Terminado</option>
        <option value="todo">Todos</option>
    </select>
    </td>-->
</tr>
</table>
</div>
<br />
<div id="txtHint" class="centrado"><b>Mostrando</b></div>
</form>
</body>
</html>
<? ?>
Segundo, donde se mostraran los datos

Código PHP:
<?php
session_start
();
if(!isset(
$_SESSION['us_id'])){
header("Location: ../index.php"); 
} else { 
$usuario=$_SESSION['us_id'];
$admin=$_SESSION['us_tipo'];

$emp=$_GET["q"];

include_once(
"conexion.php");
include(
'./Scripts/funcion.php');
    
$conexion = new ControlBD();
    
$conexion->conectar();
    
$conexion->seleccionarBD();
    
$query="SELECT req_id, em_nombre,su_nombre, us_unidad, us_cargo, us_nombre, us_apellido, us_email, us_telefono, mo_nombre, tra_maestro, req_date, req_descripcion, req_valicacion, us_tipo, req_imagen, req_archivo FROM cgrequerimientos 
           INNER JOIN cgempresa on req_idempresa=em_id 
           INNER JOIN cgusuarios on req_usuario=us_id 
           INNER JOIN cgmodulo on req_idmodulo=mo_id 
           INNER JOIN cgtransacciones on req_idtrans=tra_tipo
           INNER JOIN cgsucursal ON req_idsucursal=su_id
            WHERE req_valicacion=0 and req_estado='Activo' AND em_id = '$emp'
            ORDER BY req_id,req_date"
;
$result=$conexion->ejecutarQuery($query);
?>
<form>
<a href="javascript:imprSelec('seleccion')" >Imprimir Requerimientos</a> 
<div class="centrado">
<DIV ID="seleccion">
<table class="tablas">
    <tr>
        <th>Empresa</th>
        <th>Sucursal</th>
        <th>Ticket</th>
        <!--<th>Departamento</th>
        <th>Cargo del Solicitante</th> -->
        <th>Nombre</th>
        <th>Email</th>
        <th>Telefono</th>
        <th>Modulo</th>
        <th>Transaccion</th>
        <th>Fecha</th>
        <th>Descripcion</th>
        <th>Imagen</th>
        <th>Documentacion</th>
        <th colspan="4">Acciones</th>
    </tr>
<? while($array=mysql_fetch_array($result)){ $id=$array['req_id'];?>
    <tr>
        <td><?=$array['em_nombre']; ?></td>
        <td><?=$array['su_nombre']; ?></td>
        <td><strong><?=$array['req_id']; ?></strong></td>
        <!--<td><?=$array['us_unidad']; ?></td>
        <td><?=$array['us_cargo']; ?></td>-->
        <td><?=$array['us_nombre']." ".$array['us_apellido']; ?></td>
        <td><?=$array['us_email']; ?></td>
        <td><?=$array['us_telefono']; ?></td>
        <td><?=$array['mo_nombre']; ?></td>
        <td><?=$array['tra_maestro']; ?></td>
        <td><?=cambiar_fecha($array['req_date']); ?></td>
        <td style=" text-align:justify; font-family:Tahoma, Geneva, sans-serif; font-size:12px;">
        <? if(strlen($array['req_descripcion']) <= 120){
             echo 
$array['req_descripcion'];
         }else{
             echo 
$descri=substr($array['req_descripcion'], 0120); ?>  <a href="javascript:mostrarVentana('<?=$id;?>');"> [...] </a>
             <div id="miVentana" class="ventana" >
 <div class="ventana1">Descripcion del Requerimiento N° <?=$id;?> </div>
 <p class="pe"><?=$array['req_descripcion']; ?></p>
  <div class="bot" ><input id="btnAceptar" onClick="ocultarVentana();" name="btnAceptar" size="20" type="button" value="Aceptar" />
 </div>
</div>  
<? ?>
         </td>
        
        <td><a href="<?=$array['req_imagen']; ?>" rel="lightbox" title="imagen"><img src="<?=$array['req_imagen']; ?>" alt="imagen" width="72" height="64" /></a></td>
        
        <? $archivo=$array['req_archivo']; if(substr($archivo,-3) == 'doc'){ ?>  
        <td class="center"><a href="<?=$array['req_archivo']; ?>" title="Documentacion"><img src="images/word.png" alt="Word" width="50" height="50"  /></a></td>
        <? } if(substr($archivo,-4) == 'docx'){ ?>  
        <td class="center"><a href="<?=$array['req_archivo']; ?>" title="Documentacion"><img src="images/word.png" alt="Word" width="50" height="50"  /></a></td>
        <? } elseif(substr($archivo,-3) == 'xls'){ ?>  
        <td class="center"><a href="<?=$array['req_archivo']; ?>" title="Documentacion"><img src="images/excel.png" alt="Excel" width="50" height="50"  /></a></td>
        <? } elseif(substr($archivo,-4) == 'xlsx'){ ?>  
        <td class="center"><a href="<?=$array['req_archivo']; ?>" title="Documentacion"><img src="images/excel.png" alt="Excel" width="50" height="50"  /></a></td>
        <? } elseif(substr($archivo,-3) == 'pdf'){ ?>  
        <td class="center"><a href="<?=$array['req_archivo']; ?>" title="Documentacion"><img src="images/pdf.png" alt="Excel" width="50" height="50"  /></a></td>
        <? } else {?>
        <td class="center">No Tiene</td>
        <? ?>
        
        <td><a href="Javascript:Borrar('<?=$id;?>','Borrar_disp.php' ,'800','300')" title="Anular"><img src="./imagenes/eliminar.png" alt="Eliminar" border=0 ></a></td>
        <td><a href="javascript:Actualizar('<?=$id;?>','modificareq.php' ,'850','370')" title="Modificar"><img src="./imagenes/actualizar.png" alt="Modificar" border=0></a></td>
<? if($array['req_valicacion']==0){ ?>
        <td><a href="javascript:Validar('<?=$id;?>','activar.php' ,'800','300')" title="Validar"><img src="./imagenes/aceptar.png" alt="Agregar" border=0 ></a></td><? ?>
   
    <td><a href="javascript:Correo('<?=$id;?>','correo.php' ,'800','300')" title="Correo"><img src="./imagenes/mail.png" alt="Agregar" border=0 ></a></td>
   
    </tr>
<? ?>
</table>
</DIV>
</div>
</form>
</body>
<? }?>
En la parte donde esta req_descripcion es donde hago la validacion y limito los caracteres y le paso el id a la funcion mostrarVentana() que esta en el primer Script, espero se entienda lo que quiero lograr, ya que he intentado de todo y no me funciona de ninguna manera.
Saludos

Etiquetas: ajax, javascript+php, mysql, php
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:05.