Foros del Web » Programando para Internet » PHP »

PHP OO Consultas en php a varios registros con un campo en comun y mostrarlos

Estas en el tema de Consultas en php a varios registros con un campo en comun y mostrarlos en el foro de PHP en Foros del Web. Muy buenos días, Soy nuevo en éste portal web, pero indagando me di cuenta que podría obtener algo de ayuda con un código en PHP; ...
  #1 (permalink)  
Antiguo 26/11/2013, 10:15
 
Fecha de Ingreso: noviembre-2013
Mensajes: 1
Antigüedad: 10 años, 5 meses
Puntos: 0
Consultas en php a varios registros con un campo en comun y mostrarlos

Muy buenos días,

Soy nuevo en éste portal web, pero indagando me di cuenta que podría obtener algo de ayuda con un código en PHP; el problema es el siguiente:

Tengo una BD en phpMyAdmin llamada SISBEN que tiene una única tabla llamada fichas, en la cual hay 116.175 registros, en ella hay campos diversos, pero los que me interesan los relaciono en el código adjunto; la dificultad que tengo es que hay registros con un campo en común (Campo Fichas, tipo varchar(200), solo contienen números), tengo una consulta donde me muestra un solo registro de esa tabla, pero debajo de ese registro en una tabla adicional quiero mostrar los demás registros que también tienen asociados ese campo, pero solamente de éstos deseo ver algunos campos...

Código:

<?php require_once('Connections/conexion.php'); ?>
<?php

$txt_busqueda=$_POST["txt_busqueda"];

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_real_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_consultas = "-1";
if (isset($_GET['Numero del documento de identidad'])) {
$colname_consultas = (get_magic_quotes_gpc()) ? $_GET['Numero del documento de identidad'] : addslashes($_GET['Numero del documento de identidad']);
}
mysql_select_db($database_conexion, $conexion);
$query_consultas = sprintf("SELECT * FROM fichas WHERE `Numero del documento de identidad` = '$txt_busqueda'", $colname_consultas);
$consultas = mysql_query($query_consultas, $conexion) or die(mysql_error());
$row_consultas = mysql_fetch_assoc($consultas);
$totalRows_consultas = mysql_num_rows($consultas);
?>
<style type="text/css">
<!--
.Estilo1 {font-size: 9px}
.Estilo3 {font-size: 18px}
.Estilo4 {font-size: 16px}
-->
</style>

<form id="form2" name="form2" method="post"action="">
<table width="738" border="1" align="center" bordercolor="#000000">
<tr>
<td colspan="3"><div align="center"><span class="Estilo3 Estilo9"><strong>INFORMACI&Oacute;N DEL SOLICITANTE</strong></span> </div></td>
</tr>
<tr class="Estilo4">
<td width="244"><span class="Estilo4">Nombres:</span></td>
<td width="238"><span class="Estilo3"><?php echo $row_consultas['Nombre1']; ?></span></td>
<td width="234"><span class="Estilo3"><?php echo $row_consultas['Nombre2']; ?></span></td>
</tr>
<tr class="Estilo4">
<td><span class="Estilo4">Apellidos:</span></td>
<td><span class="Estilo3"><?php echo $row_consultas['Apellidos1']; ?></span></td>
<td><span class="Estilo3"><?php echo $row_consultas['Apellidos2']; ?></span></td>
</tr>
<tr class="Estilo4">
<td><span class="Estilo4">Tipo Documento:</span></td>
<td colspan="2"><span class="Estilo3"><?php echo $row_consultas['Tipo de documento de identidad']; ?></span></td>
</tr>
<tr class="Estilo4">
<td><span class="Estilo4">N&uacute;mro de Documento:</span></td>
<td colspan="2"><span class="Estilo3"><?php echo $row_consultas['Numero del documento de identidad']; ?></span></td>
</tr>
<tr class="Estilo4">
<td><span class="Estilo4">&Aacute;rea:</span></td>
<td colspan="2"><span class="Estilo3"><?php echo $row_consultas['Zona']; ?></span></td>
</tr>
<tr class="Estilo4">
<td><span class="Estilo4">Ficha:</span></td>
<td colspan="2"><span class="Estilo3"><?php echo $row_consultas['Ficha']; ?></span></td>
</tr>
<tr class="Estilo4">
<td><span class="Estilo4">Fecha de Encuesta:</span></td>
<td colspan="2"><span class="Estilo3"><?php echo $row_consultas['Fecha de encuesta']; ?></span></td>
</tr>
<tr class="Estilo4">
<td colspan="3"><div align="center"><span class="Estilo4">Base Certificada Municipalmente. Corte: 18 de Octubre de 2013 </span></div></td>
</tr>
<tr>
<td colspan="3"><div align="center"><span class="Estilo7 Estilo1">La informaci&oacute;n aqu&iacute; registrada debe ser verificada en la p&aacute;gina web www.sisben.gov.co opci&oacute;n consulta de puntaje</span></div></td>
</tr>
<tr>
<td colspan="3"><div align="center"><span class="Estilo3 Estilo9"><strong>INFORMACI&Oacute;N DEL N&Uacute;CLEO FAMILIAR </strong></span></div></td>
</tr>
<tr>
<td colspan="3">Aqui quiero que aparezcan todas las personas que estan registradas en la BD, con el mismo numero de ficha (Ficha) </td>
</tr>
</table>
</form>
<?php
mysql_free_result($consultas);
?>

<form id="form3" action="" method="post" name="Form3">
<?php
$colname_consultas = "-1";
if (isset($_GET['Ficha'])) {
$colname_consultas = (get_magic_quotes_gpc()) ? $_GET['Ficha'] : addslashes($_GET['Ficha']);
}
mysql_select_db($database_conexion, $conexion);
$query_consultas = sprintf("SELECT * FROM fichas WHERE `Ficha` = 'Ficha'", $colname_consultas);
$consultas = mysql_query($query_consultas, $conexion) or die(mysql_error());
$row_consultas = mysql_fetch_assoc($consultas);
$totalRows_consultas = mysql_num_rows($consultas);
echo '<table width"400" border="3" align="center"> <tr> <th bgcolor="#CCFF00">Ficha</th> <th>Doc. Identidad</th> <th>Apellido 1</th> <th>Apellido 2</th> <th>Nombre 1</th> <th>Nombre 2</th> </tr>';
while ($row=mysql_fetch_array($result)){
echo '<td bgcolor="#CCFF00" align="center">'.$row["Ficha"].'</td>';
echo '<td align="center">'.$row_consultas["Numero del documento de identidad"].'</td>';
echo '<td align="center">'.$row_consultas["Apellido1"].'</td>';
echo '<td align="center">'.$row_consultas["Apellido2"].'</td>';
echo '<td align="center">'.$row_consultas["Nombre1"].'</td>';
echo '<td align="center">'.$row_consultas["Nombre2"].'</td>';
echo "<tr>";
}
?>
</form>

</body>
</html>


[IMG]https://docs.google.com/file/d/0B0nfDMee_ap9TWg1QktuYmx1UUU/edit[/IMG
]

Etiquetas: campo, fecha, html, mysql, registro, registros, select, sql, 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 12:36.