Foros del Web » Programando para Internet » PHP »

Necesito generar una consulta dentro de otra

Estas en el tema de Necesito generar una consulta dentro de otra en el foro de PHP en Foros del Web. Necesito que la consulta abril se ejecute en cada registro de la consulta nombres y unicamente se visualiza la primera vez o sea en el ...
  #1 (permalink)  
Antiguo 19/07/2011, 11:44
 
Fecha de Ingreso: julio-2011
Ubicación: Los Rios
Mensajes: 145
Antigüedad: 12 años, 9 meses
Puntos: 10
Busqueda Necesito generar una consulta dentro de otra

Necesito que la consulta abril se ejecute en cada registro de la consulta nombres y unicamente se visualiza la primera vez o sea en el primer registro y deseo que los mismos datos se reflejen en cada uno de los registros de nombres.. favor si pueden ayudarme estare muy agradecido


<?php require_once('Connections/miconexion.php'); ?><?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;
}
}

$colname_nombres = "-1";
if (isset($_POST['curso'])) {
$colname_nombres = $_POST['curso'];
}
mysql_select_db($database_miconexion, $miconexion);
$query_nombres = sprintf("SELECT mmateria, mcurso FROM materia WHERE mcurso = %s ORDER BY mmateria ASC", GetSQLValueString($colname_nombres, "text"));
$nombres = mysql_query($query_nombres, $miconexion) or die(mysql_error());
$row_nombres = mysql_fetch_assoc($nombres);
$totalRows_nombres = mysql_num_rows($nombres);

$colname_abril = "-1";
if (isset($_POST['estudiante'])) {
$colname_abril = $_POST['estudiante'];
}
$mes_abril = "-1";
if (isset($_POST['m1'])) {
$mes_abril = $_POST['m1'];
}
mysql_select_db($database_miconexion, $miconexion);
$query_abril = sprintf("SELECT codigo, est, ac, td, tg, la, `as`, punt, uni, comp FROM nota WHERE codigo LIKE %s and codigo LIKE %s", GetSQLValueString("%" . $colname_abril . "%", "text"),GetSQLValueString("%" . $mes_abril . "%", "text"));
$abril = mysql_query($query_abril, $miconexion) or die(mysql_error());
$row_abril = mysql_fetch_assoc($abril);
$totalRows_abril = mysql_num_rows($abril);
?>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>mmateria</td>
<td>mcurso</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_nombres['mmateria']; ?></td>
<td><table border="0" cellpadding="0" cellspacing="0">
<tr> </tr>
<?
reset($abril);
do { ?>
<tr>
<td><?php echo $row_abril['codigo']; ?></td>
<td>&nbsp;</td>
<td><?php
echo $row_abril['ac']+$row_abril['td']+ $row_abril['tg']+ $row_abril['la'];
echo "-";
echo $row_abril['as']+$row_abril['punt']+$row_abril['uni']+$row_abril['comp']; ?></td>
</tr>
<?php } while ($row_abril = mysql_fetch_assoc($abril)); ?>
</table></td>
</tr>
<?php } while ($row_nombres = mysql_fetch_assoc($nombres)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($nombres);

mysql_free_result($abril);
?>
  #2 (permalink)  
Antiguo 20/07/2011, 00:36
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Necesito generar una consulta dentro de otra

http://www.forosdelweb.com/f18/php-m...sultas-930525/
__________________
Fere libenter homines, id quod volunt, credunt.

Etiquetas: 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 07:14.