Foros del Web » Programando para Internet » PHP »

mostrar variable si tiene contenido

Estas en el tema de mostrar variable si tiene contenido en el foro de PHP en Foros del Web. Hola a todos. Necesitaría un poco de guia y/o ayuda. Los clientes dejan sus comentarios y estos se almacenan en mi BD, pero no todos ...
  #1 (permalink)  
Antiguo 22/02/2012, 15:01
 
Fecha de Ingreso: agosto-2008
Ubicación: Miami, FL
Mensajes: 210
Antigüedad: 15 años, 8 meses
Puntos: 2
Pregunta mostrar variable si tiene contenido

Hola a todos.
Necesitaría un poco de guia y/o ayuda.
Los clientes dejan sus comentarios y estos se almacenan en mi BD, pero no todos los clientes dejan comentarios.
Lo que necesito es saber como mostrar por ejemplo un texto que diga "comentario" cuando hay y al hacer click mostrarlo, pop up, debajo, al lado, me da igual, siempre que después de leerlo lo pueda cerrar.
El código que utilizo es el siguiente:

.....//
$datos_sql = mysql_query("SELECT * FROM datos ORDER BY personalID DESC limit " . $limit[0] . ', ' . $limit[1]);

echo "
<table class='css3' id='mytable' cellspacing='0'>
<tr class='nobg'>
<th scope='col'><strong>Personal ID</strong</th>
<th scope='col'><strong>Date</strong></th>
<th scope='col'><strong>Client Information</strong></th>
<th scope='col'><strong>Vehicle Information</strong></th>
<th scope='col'><strong>Comment</th>
<th scope='col'><strong>Pickup/Dropoff</strong></th>
<th scope='col'><strong>Shipping On</strong></th>
<th scope='col'><strong>Pre/Quote</strong></th>
<th class='title' scope='col'>Pre/Quote</th>
<th class='title' scope='col'>Quote</th>
<th class='title' scope='col'>Email</th>
<th class='title' scope='col'>Archive</th>
<th class='title' scope='col'>Delete</th>
</tr>

";

while ($fila = mysql_fetch_array($datos_sql))
{
echo"
<tr class='spec' >
<td align=center>ID: ".$fila['personalID']."</td>
<td align=center>".$fila['fecha_registro']."</td>
<td>".$fila['first_name']." ".$fila['last_name']."<br />".$fila['phone']."<br />".$fila['email']."</td>
<td>".$fila['year1']." ".$fila['make1']." ".$fila['model1']."<br />".$fila['vehicle_type_id1']." <strong>Runs?:</strong>(".$fila['vehicle_runs'].")<br />".$fila['vehicle_type_other1']."</td>
<td>".$fila['comment']."</td>
<td><strong>From: </strong>".$fila['pickup_city']."
.......//

se puede hacer de alguna forma?

desde ya muchas gracias.
  #2 (permalink)  
Antiguo 22/02/2012, 15:33
Avatar de jcMouse  
Fecha de Ingreso: noviembre-2009
Ubicación: Bolivia
Mensajes: 116
Antigüedad: 14 años, 5 meses
Puntos: 9
Respuesta: mostrar variable si tiene contenido

if($datos_sql!=NULL)
{
//creas la tabla y llenas los datos
}
else
{
echo 'No tiene comentarios';
}
__________________
Problem?
Estoy aquí
Foro Code Army
  #3 (permalink)  
Antiguo 22/02/2012, 16:00
 
Fecha de Ingreso: agosto-2008
Ubicación: Miami, FL
Mensajes: 210
Antigüedad: 15 años, 8 meses
Puntos: 2
Respuesta: mostrar variable si tiene contenido

hola jcMouse,
Gracias por tu respuesta, pero no lo entiendo o no me has entendido.
La tabla se crea igual, mas allá que haya o no "comentarios" ya que muestra otros datos,
mi problema toca solo a la variable $fila['comment'].
Se me ocurre algo como:

if($fila['comment']!=NULL)
{
// no muestra nada
}else{

y aqui es donde tengo la duda, como muestro el comentario en la sección de la tabla (<td>comentario</td>)? o todo este código (if...) va dentro de <td></td>?
}

Gracias por tu tiempo
  #4 (permalink)  
Antiguo 22/02/2012, 16:09
Avatar de charly_vc  
Fecha de Ingreso: enero-2012
Ubicación: GDL
Mensajes: 31
Antigüedad: 12 años, 3 meses
Puntos: 1
Respuesta: mostrar variable si tiene contenido

Porque no encierras el codigo html que quieres que se muestre dentro del if??, solo seria un simple

<?if(trim($fila['comment']) != ""){?>
.
.
tu codigo html aqui...
.
.
<?}?>

Ó bien usa un include a otro archivo php donde tienes el codigo que pinta los comentarios y todo el rollo

<?if(trim($fila['comment']) != ""){
include "tuArchivo.php";
}
?>
  #5 (permalink)  
Antiguo 22/02/2012, 16:15
 
Fecha de Ingreso: agosto-2008
Ubicación: Miami, FL
Mensajes: 210
Antigüedad: 15 años, 8 meses
Puntos: 2
Respuesta: mostrar variable si tiene contenido

hola Chayly_vc, en realidad este es un archivo llamado mostrarresultados.php que va incluido dentro de un html. El código completo es el siguientes:

<?php

session_start();

//1. Crear conexión a la Base de Datos
$conexion = mysql_connect("localhost","","");
if (!$conexion) {
die("Fallo la conexión a la Base de Datos: " . mysql_error());
}
//2. Seleccionar la Base de Datos a utilizar
$seleccionar_bd = mysql_select_db("", $conexion);
if (!$seleccionar_bd) {
die("Fallo la selección de la Base de Datos: " . mysql_error());
}

// Con esto tenemos el total de autos en nuestra tabla 'autos'
$contador_datos_sql = 'select count(*) from datos' ;
$contador_datos_result = mysql_query($contador_datos_sql) ;
$total_datos = mysql_result($contador_datos_result, 0, 0) ;

// configuración de la clase
include('class.kpaginate.php') ; // incluimos la clase
$kp1 = new kpaginate ; // instanciamos la clase
$kp1->setTotalItems($total_datos) ; // OJO!, aquí ponemos el total de autos que conseguimos anteriormente
$kp1->setItemsPerPage(10) ; // 5 = cuantos autos queremos mostrar por página
$limit = $kp1->getLimit() ; // IMPORTANTE: Este metodo retorna un array con 2 valores, el primero es el límite inferior y el segundo el límite superior que debemos colocar en nuestra consulta, veamos...

$datos_sql = mysql_query("SELECT * FROM datos ORDER BY personalID DESC limit " . $limit[0] . ', ' . $limit[1]);

echo "
<table class='css3' id='mytable' cellspacing='0'>
<tr class='nobg'>
<th scope='col'><strong>Personal ID</strong</th>
<th scope='col'><strong>Date</strong></th>
<th scope='col'><strong>Client Information</strong></th>
<th scope='col'><strong>Vehicle Information</strong></th>
<th scope='col'><strong>Comment</th>
<th scope='col'><strong>Pickup/Dropoff</strong></th>
<th scope='col'><strong>Shipping On</strong></th>
<th scope='col'><strong>Pre/Quote</strong></th>
<th class='title' scope='col'>Pre/Quote</th>
<th class='title' scope='col'>Quote</th>
<th class='title' scope='col'>Email</th>
<th class='title' scope='col'>Archive</th>
<th class='title' scope='col'>Delete</th>
</tr>

";

while ($fila = mysql_fetch_array($datos_sql))
{
echo"
<tr class='spec' >
<td align=center>ID: ".$fila['personalID']."</td>
<td align=center>".$fila['fecha_registro']."</td>
<td>".$fila['first_name']." ".$fila['last_name']."<br />".$fila['phone']."<br />".$fila['email']."</td>
<td width='200px'>".$fila['year1']." ".$fila['make1']." ".$fila['model1']."<br />".$fila['vehicle_type_id1']." <strong>Runs?:</strong>(".$fila['vehicle_runs'].")<br />".$fila['vehicle_type_other1']."</td>
<td width='200px'>".$fila['comment']."</td>
<td><strong>From: </strong>".$fila['pickup_city']."-".$fila['zip_code_pickup']."<br />".$fila['pickup_state_code']."-".$fila['pickup_country_id']."<br /><strong>To: </strong>".$fila['dropoff_city']."-".$fila['zip_code_dropoff']."-".$fila['dropoff_state_code']."<br />".$fila['dropoff_country_id']." <a href='mapa.php?zip_code_pickup=".$fila['zip_code_pickup']."&pickup_city=".$fila['pickup_city']."&zip_code_dropoff=".$fila['zip_code_dropoff']."&dropoff_city=".$fila['dropoff_city']."' target=_blank >route map</a> / <a href='http://maps.google.com/maps?hl=en&tab=wl' target=_blank>map</a></td>
<td align=center>".$fila['estimated_ship_date']."</td>
<td align=center>$: ".$fila['estimado']."</td>
<td align=center><a href='formprequote.php?personalID=".$fila['personalID']."&first_name=".$fila['first_name']."&last_name=".$fila['last_name']."&phone=".$fila['phone']."&email=".$fila['email']."&year1=".$fila['year1']."&make1=".$fila['make1']."&model1=".$fila['model1']."&vehicle_type_id1=".$fila['vehicle_type_id1']."&vehicle_runs=".$fila['vehicle_runs']."&vehicle_type_other1=".$fila['vehicle_type_other1']."&comment=".$fila['comment']."&pickup_city=".$fila['pickup_city']."&zip_code_pickup=".$fila['zip_code_pickup']."&pickup_state_code=".$fila['pickup_state_code']."&pickup_country_id=".$fila['pickup_country_id']."&dropoff_city=".$fila['dropoff_city']."&zip_code_dropoff=".$fila['zip_code_dropoff']."&dropoff_state_code=".$fila['dropoff_state_code']."&dropoff_country_id=".$fila['dropoff_country_id']."&estimated_ship_date=".$fila['estimated_ship_date']."&estimado=".$fila['estimado']."'><img src='images/icon_pre_quote.png'></a></td>
<td align=center><a href='quote_spanish.php?personalID=".$fila['personalID']."&first_name=".$fila['first_name']."&last_name=".$fila['last_name']."&phone=".$fila['phone']."&email=".$fila['email']."&year1=".$fila['year1']."&make1=".$fila['make1']."&model1=".$fila['model1']."&vehicle_type_id1=".$fila['vehicle_type_id1']."&vehicle_runs=".$fila['vehicle_runs']."&vehicle_type_other1=".$fila['vehicle_type_other1']."&pickup_city=".$fila['pickup_city']."&zip_code_pickup=".$fila['zip_code_pickup']."&pickup_state_code=".$fila['pickup_state_code']."&pickup_country_id=".$fila['pickup_country_id']."&dropoff_city=".$fila['dropoff_city']."&zip_code_dropoff=".$fila['zip_code_dropoff']."&dropoff_state_code=".$fila['dropoff_state_code']."&dropoff_country_id=".$fila['dropoff_country_id']."&estimated_ship_date=".$fila['estimated_ship_date']."&estimado=".$fila['estimado']."' target=_blank><img src='images/icon_quote.png'></a></td>
<td align=center><a href='mostraremail.php?first_name=".$fila['first_name']."&last_name=".$fila['last_name']."&email=".$fila['email']."' target=_blank><img src='images/icon_email.png'></a></td>
<td align=center><a onclick='return archivar()' href='archive_leads.php?personalID=".$fila['personalID']."&first_name=".$fila['first_name']."&last_name=".$fila['last_name']."&phone=".$fila['phone']."&email=".$fila['email']."&year1=".$fila['year1']."&make1=".$fila['make1']."&model1=".$fila['model1']."&vehicle_type_id1=".$fila['vehicle_type_id1']."&vehicle_runs=".$fila['vehicle_runs']."&vehicle_type_other1=".$fila['vehicle_type_other1']."&comment=".$fila['comment']."&pickup_city=".$fila['pickup_city']."&zip_code_pickup=".$fila['zip_code_pickup']."&pickup_state_code=".$fila['pickup_state_code']."&pickup_country_id=".$fila['pickup_country_id']."&dropoff_city=".$fila['dropoff_city']."&zip_code_dropoff=".$fila['zip_code_dropoff']."&dropoff_state_code=".$fila['dropoff_state_code']."&dropoff_country_id=".$fila['dropoff_country_id']."&estimated_ship_date=".$fila['estimated_ship_date']."&estimado=".$fila['estimado']."'><img src='images/icon_archive_leads.png'></a></td>
<td align=center><a onclick='return eliminar()' href='eliminarregistro.php?personalID=".$fila['personalID']."&first_name=".$fila['first_name']."&last_name=".$fila['last_name']."&phone=".$fila['phone']."&email=".$fila['email']."&year1=".$fila['year1']."&make1=".$fila['make1']."&model1=".$fila['model1']."&vehicle_type_id1=".$fila['vehicle_type_id1']."&vehicle_runs=".$fila['vehicle_runs']."&vehicle_type_other1=".$fila['vehicle_type_other1']."&comment=".$fila['comment']."&pickup_city=".$fila['pickup_city']."&zip_code_pickup=".$fila['zip_code_pickup']."&pickup_state_code=".$fila['pickup_state_code']."&pickup_country_id=".$fila['pickup_country_id']."&dropoff_city=".$fila['dropoff_city']."&zip_code_dropoff=".$fila['zip_code_dropoff']."&dropoff_state_code=".$fila['dropoff_state_code']."&dropoff_country_id=".$fila['dropoff_country_id']."&estimated_ship_date=".$fila['estimated_ship_date']."&estimado=".$fila['estimado']."'><img src='images/icon_delete.png'></a></td>
</tr>
";
}
echo "</tabla>";
// Al final imprimimos la paginación, ya saben, los numeritos...
$kp1->paginate() ;

$_SESSION['personalID'] = $personalID;

mysql_close($conexion);

?>
  #6 (permalink)  
Antiguo 22/02/2012, 18:04
 
Fecha de Ingreso: febrero-2012
Ubicación: En mi propio mundo
Mensajes: 73
Antigüedad: 12 años, 2 meses
Puntos: 23
Respuesta: mostrar variable si tiene contenido

Si no te he entendido mal quieres mostrar u ocultar los datos de la tabla de comentarios mediante un botón no¿?. Si es asi lo mas sencillo es usar jquery (javascript)
  #7 (permalink)  
Antiguo 22/02/2012, 21:19
 
Fecha de Ingreso: agosto-2008
Ubicación: Miami, FL
Mensajes: 210
Antigüedad: 15 años, 8 meses
Puntos: 2
Respuesta: mostrar variable si tiene contenido

Hola Fierox,
La verdad es que si, en este momento lo tengo con css ocultando y mostrando, el problema es que me oculta todos al presionar el boton.
Si tuvieras algun codigo para que pudiera echarle un vistaso te lo agradeceria mucho.

gracias

Etiquetas: variablesphp
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 02:02.