Foros del Web » Programando para Internet » PHP »

Ayuda con while

Estas en el tema de Ayuda con while en el foro de PHP en Foros del Web. Hola: Estoy trabajando con una tabla que muestra los resultados de una página de búsqueda y de manera general la tabla generada se despliega bien, ...
  #1 (permalink)  
Antiguo 06/08/2008, 08:13
 
Fecha de Ingreso: febrero-2007
Mensajes: 18
Antigüedad: 17 años, 2 meses
Puntos: 0
Ayuda con while

Hola:

Estoy trabajando con una tabla que muestra los resultados de una página de búsqueda y de manera general la tabla generada se despliega bien, pero no muestra los resultados completos, por ejemplo si la búsqueda debería arrojar 13 resultados solo aparecen 12, me parece que el error esta en la siguiente linea:

while($row_reportes=mysql_fetch_assoc($reportes)){

De cualquier forma, aqui dejo el código el cual gran parte ha sido generado en dreamweaver.

De antemano agradezco cualquier ayuda.

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}


$diavar_reportes = "-1";
if (isset($_GET['dia'])) {
$diavar_reportes = $_GET['dia'];
}
$idmodulovar_reportes = "-1";
if (isset($_GET['idmodulo'])) {
$idmodulovar_reportes = $_GET['idmodulo'];
}
$ciclovar_reportes = "-1";
if (isset($_GET['idciclo'])) {
$ciclovar_reportes = $_GET['idciclo'];
}
$idmaestrovar_reportes = "-1";
if (isset($_GET['idmaestro'])) {
$idmaestrovar_reportes = $_GET['idmaestro'];
}
$anovar_reportes = "-1";
if (isset($_GET['ano'])) {
$anovar_reportes = $_GET['ano'];
}
$mesvar_reportes = "-1";
if (isset($_GET['mes'])) {
$mesvar_reportes = $_GET['mes'];
}
mysql_select_db($database_uceh, $uceh);
$query_reportes = sprintf("SELECT * FROM reportes r, alumnos a, maestros m, ciclos c, modulos mo, materias ma, anoescolar an WHERE r.dia = %s AND r.mes=%s AND r.ano=%s AND r.idmaestro=%s AND r.idciclo=%s AND r.idmodulo=%s AND r.idmodulo=mo.idmodulo AND r.matricula=a.matricula AND r.idmaestro=m.idmaestro AND r.idciclo=c.idciclo AND r.materia=ma.idmateria AND r.idanoescolar=an.idanoescolar ORDER BY a.nombre", GetSQLValueString($diavar_reportes, "text"),GetSQLValueString($mesvar_reportes, "text"),GetSQLValueString($anovar_reportes, "text"),GetSQLValueString($idmaestrovar_report es, "text"),GetSQLValueString($ciclovar_reportes, "text"),GetSQLValueString($idmodulovar_reporte s, "text"));
$reportes = mysql_query($query_reportes, $uceh) or die(mysql_error());
$row_reportes = mysql_fetch_assoc($reportes);
$totalRows_reportes = mysql_num_rows($reportes);
?><!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" />

<title>panel</title>

<style type="text/css">
<!--
.style1 { font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #AC2326;
font-weight: bold;
}
.style2 { font-family: Arial, Helvetica, sans-serif;
color: #AC2326;
font-weight: bold;
}
-->
</style>




<style type="text/css">
<!--
.style1 { font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #AC2326;
font-weight: bold;
}
.style2 { font-family: Arial, Helvetica, sans-serif;
color: #AC2326;
font-weight: bold;
}
-->
</style>

<link href="../css.css" rel="stylesheet" type="text/css" />


<link href="../css.css" rel="stylesheet" type="text/css" />
</head>

<body bgcolor="#AF1E21">
<form id="form1" name="form1" method="post" action="okreportedia.php">
<p class="textomedio">&nbsp;</p>
<table border="1" cellpadding="3" cellspacing="0">
<tr class="fondoamarillooscuro">
<td>ID</td>
<td>alumno</td>
<td>matricula</td>
</tr>
<?
// Fetch record rows in $result by while loop and put them into $row.

while($row_reportes=mysql_fetch_assoc($reportes)){
?>
<tr class="textomedio">
<td><? echo $row_reportes['idreportes']; // Show record's ID ?>
<input name="reportado_<? echo $row_reportes['idreportes']; ?>" type="hidden" id="reportado_<? echo $row_reportes['idreportes']; ?>" value="si" /></td>
<td class="textomedio"><?php echo $row_reportes['nombre']; ?></td>
<td class="textomedio"><?php echo $row_reportes['matricula']; ?></td>
</tr>
<? } // End while loop. ?>
</table>
<input type="submit" name="Submit" value="Update" />
</form>
</body>
</html>
<?php
mysql_free_result($reportes);

?>
  #2 (permalink)  
Antiguo 06/08/2008, 08:22
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: Ayuda con while

Quita esta linea:
Código PHP:
$row_reportes mysql_fetch_assoc($reportes); 
Después de tu MySQL Query.

Saludos.
  #3 (permalink)  
Antiguo 06/08/2008, 19:55
 
Fecha de Ingreso: febrero-2007
Mensajes: 18
Antigüedad: 17 años, 2 meses
Puntos: 0
Respuesta: Ayuda con while

Muchas gracias por la ayuda, he quitado la linea que me ha sugerido y el resultado ya es correcto, solo que me crea un inconveniente, la tabla que genera el resultado es para actualizar la información de la base de datos, y al darle update si me actualiza los registros, pero ahora me borra todos los demás... aqui dejo el código de la página que hace el update:

<?php
if($_POST['Submit']){ // If receive Submit button variable.


// Select all data records in table "reportes" and put them into $result.
$result=mysql_query("select idreportes from reportestest order by idreportes asc");

// Fetch record rows in $result by while loop and put them into $row.
while($row1=mysql_fetch_assoc($result)){
// Get the posted value "name_ID value" from form.php. This variable change it's value by while loop.
$reportado=$_POST["reportado_".$row1[idreportes]];
$retardos=$_POST["retardos_".$row1[idreportes]];
$faltas=$_POST["faltas_".$row1[idreportes]];

// Update field "name", matching with "id" value by while loop.
mysql_query("update reportestest set reportado='$reportado', retardos='$retardos', faltas='$faltas' where idreportes='$row1[idreportes]'");
}
echo "--- Actualización completa ---";
}

?>
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:29.