Foros del Web » Programando para Internet » PHP »

Borrar fila con condicion

Estas en el tema de Borrar fila con condicion en el foro de PHP en Foros del Web. Buenos dias, tengo un problema a la hora de mostrar los datos en una pagina desde una base de datos y os escribo por si ...
  #1 (permalink)  
Antiguo 23/07/2014, 02:48
 
Fecha de Ingreso: julio-2014
Mensajes: 53
Antigüedad: 9 años, 9 meses
Puntos: 1
Borrar fila con condicion

Buenos dias, tengo un problema a la hora de mostrar los datos en una pagina desde una base de datos y os escribo por si pudierais hacerme el favor de intentar ayudarme:

Tengo un documento .php en el que hay una tabla con los mismos valores que hay en mi base de datos en phpmyadmin. Hay algunos valores, como por ejemplo "Lengua de traduccion 25" que no son rellenados (a veces no se traduce un documento en 25 lenguas) y salen por defecto como "Ninguna". Lo que no quiero es que en esta pagina me salgan las filas "Lengua de traduccion 20", "Lengua de traduccion 21", etc. si estas tienen el valor de "ninguna". A alguien se le ocurre algun codigo para hacerlo?

Muchas gracias de antemano!
  #2 (permalink)  
Antiguo 25/07/2014, 05:50
 
Fecha de Ingreso: julio-2014
Mensajes: 53
Antigüedad: 9 años, 9 meses
Puntos: 1
Respuesta: Borrar fila con condicion

Estoy bastante cerca de lograrlo, y para eso tengo una funcion que deberia hacerlo pero me salta este error: ( ! ) Fatal error: Call to undefined function borrarColumna() in C:\wamp\www\SIENS\admin\VistaPresupuestos(Pgmaestr a).php on line 133

Es raro porque llamo a la funcion correctamente... Os pongo el codigo:

<?php require_once('../Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = "SELECT * FROM presupuestos";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<!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=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
A {
border-radius: 8px;
text-decoration: none;
;
color: #FFF;
}

-->
.border {
border-radius: 8px;
}
.titulo {
color: #FFF;
font-weight: bold;
}
.datos {
color: #FFF;
}
</style>
</head>

<body>
<table border="0" align="center" cellpadding="10" cellspacing="2" id="tablita">
<tr bgcolor="#0000CC" class="titulo">
<td>Nombre</td>
<?php if ($totalRows_Recordset1 > 0) { // Show if recordset not empty ?>
<td>Lengua source 1</td>
<td>Lengua source 2</td>
if($row_Recordset1['Lengua source 3'] !="") {
<td>Lengua source 3</td>
<td>Lengua target 1</td>
<td>Lengua target 2</td>
<td>Lengua target 3</td>
<script>
function borrarColumna(idTabla,numeroColumna)
{
var fila;
fila=document.getElementById(idTabla).getElementsB yTagName('tr');
ultimaColumna=fila.length
for(var i=0;i<ultimaColumna;i++)
fila[i].getElementsByTagName('td')[numeroColumna].style.display="none";
}
</script>

<?php } // Show if recordset not empty ?>
<td>Importe total</td>
</tr>
<?php do { ?>
<tr bgcolor="#0066FF" class="datos">
<td><a href="VistaPresupuestos.php?recordID=<?php echo $row_Recordset1['Nombre']; ?>"> <?php echo $row_Recordset1['Nombre']; ?>&nbsp; </a></td>

<td><?php echo $row_Recordset1['Lengua source 1']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['Lengua source 2']; ?>&nbsp; </td>
<td><?php if($row_Recordset1['Lengua source 3'] !="") {
echo $row_Recordset1['Lengua source 3'];}
else {borrarColumna('tablita',4);}
?>&nbsp; </td>

<td><?php echo $row_Recordset1['Lengua target 1']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['Lengua target 2']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['Lengua target 3']; ?>&nbsp; </td>
<td><?php echo $row_Recordset1['Importe total']; ?>&nbsp; </td>
<?php // Show if recordset not empty ?>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<br />
<table border="0">
<tr>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">Primero</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Anterior</a>
<?php } // Show if not first page ?></td>
<td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Siguiente</a>
<?php } // Show if not last page ?></td>
<td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Último</a>
<?php } // Show if not last page ?></td>
</tr>
</table>
Registros <?php echo ($startRow_Recordset1 + 1) ?> a <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> de <?php echo $totalRows_Recordset1 ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
</br></br>
<input type="button" value="Volver atrás" onClick="location.href='http://localhost/SIENS/IndiceVisualizador.html';" style="font-family: Verdana; font-size: 10 pt"/>
  #3 (permalink)  
Antiguo 25/07/2014, 06:11
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Borrar fila con condicion

Una pregunta...
¿Has considerado que esto es JavaScript:
Código Javascript:
Ver original
  1. <script>
  2. function borrarColumna(idTabla,numeroColumna)
  3. {
  4. var fila;
  5. fila=document.getElementById(idTabla).getElementsB yTagName('tr');
  6. ultimaColumna=fila.length
  7. for(var i=0;i<ultimaColumna;i++)
  8. fila[i].getElementsByTagName('td')[numeroColumna].style.display="none";
  9. }
  10. </script>
y esto otro es PHP:
Código PHP:
Ver original
  1. <?php if($row_Recordset1['Lengua source 3'] !="") {
  2. echo $row_Recordset1['Lengua source 3'];}
  3. else {borrarColumna('tablita',4);}
  4. ?>
Son lenguajes completamente diferentes, que se ejecutan en diferentes entornos. JS es en el cliente (navegador) y PHP en servidor.

Te está diciendo que la función no está definida, porque no existe en PHP una función llamada así.

¿Tienes clara la diferencia entre ambas cosas?
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #4 (permalink)  
Antiguo 25/07/2014, 11:59
 
Fecha de Ingreso: julio-2014
Mensajes: 53
Antigüedad: 9 años, 9 meses
Puntos: 1
Respuesta: Borrar fila con condicion

De acuerdo, lo entiendo. Pero segun tengo entendido seria practicamente imposible realizar una funcion en php que te haga lo que hace esta funcion JS, verdad? Entonces, tienes alguna idea de como hacerlo?

Gracias por tu respuesta!
  #5 (permalink)  
Antiguo 25/07/2014, 12:12
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 4 meses
Puntos: 2658
Respuesta: Borrar fila con condicion

Cita:
Pero segun tengo entendido seria practicamente imposible realizar una funcion en php que te haga lo que hace esta funcion JS, verdad
Quita lo de "prácticamente".
Es imposible.

Técnicamente hablando, lo que quieres hacer, interactuar en forma dinámica entre la pagina y el servidor, sólo podrías hacerlo con Ajax.
Eso hasta lo que entiendo.

AJAX Ya

Aprendiendo Ajax – Tutorial Básico


Curso de Ajax
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)

Etiquetas: fila, tabla
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 05:42.