Foros del Web » Programando para Internet » PHP »

Php y Mysql consultas..

Estas en el tema de Php y Mysql consultas.. en el foro de PHP en Foros del Web. deseo generara la consulta dentro de otra... y que la consulta abril se genere por cada registro de la consulta nombres... esta es la codificacion: ...
  #1 (permalink)  
Antiguo 19/07/2011, 13:18
 
Fecha de Ingreso: julio-2011
Ubicación: Los Rios
Mensajes: 145
Antigüedad: 12 años, 9 meses
Puntos: 10
Php y Mysql consultas..

deseo generara la consulta dentro de otra... y que la consulta abril se genere por cada registro de la consulta nombres... esta es la codificacion: please


Código HTML:
<?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:27
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: Php y Mysql consultas..

Lo que necesitas es algo así:

Código PHP:
Ver original
  1. <?php
  2. $sql = "SELECT * FROM users;";
  3. if(!$query = mysql_query($sql))die("Imposible realizar consulta!");
  4. //Recorres la consulta, para cada usuario buscamos sus caracteristicas
  5. while($fetch = mysql_fetch_assoc($query)){
  6.     $sql = "SELECT * FROM properties WHERE user_id = '{$fetch['iser_id']}'";
  7.     if(!$innerQuery = mysql_query($sql))die("Imposible realizar consulta!");
  8.     while($innerFetch = mysql_fetch_assoc($innerQuery)){
  9.         /**
  10.          * Aqui el codigo que tu quieras....
  11.          */
  12.     }//Fin de consulta interna
  13. }//Fin de consulta externa
  14. ?>
Salu2!
__________________
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 14:16.