Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/02/2012, 15:12
lrvizuete87
 
Fecha de Ingreso: febrero-2012
Ubicación: Quito
Mensajes: 1
Antigüedad: 12 años, 2 meses
Puntos: 0
Información como puedo hacer subconsultas en php y mysql

Hola amigos de Foros del Web.... He realizado este foro con el fin de resolver una inquietud.... debo hacer una consulta de impique o bien un solo parametro o varios parametros... el problema es q mi consulta puede ser id_canal,nombre_canal ó solo para buscar id_canal... el problema esq no se como unir el AND y el OR en la sentencia SQL... el codigo fuente es el siguiente....

<?php
require_once('php/conexion_usuarios.php');
require_once('php/funciones_generales.php');
?>

<!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>Reporte de Canales</title>
<link href="103x/style.css" rel="stylesheet" type="text/css" />
<link href="103x/tabla.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="post" action="">
<p><a href="RPTReporte12.php">Nueva Busqueda</a>
</p>
<p>
<?php
if(isset($_POST['borrar']))
{
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=canales.xls");

header("Pragma: no-cache");
header("Expires: 0");
exit();
exit();

}



?>

</p>
</form>
<p>
<?
if ($_POST['buscador'])
{
// Tomamos el valor ingresado
$buscar=explode(',',$_POST['palabra']);

// Si está vacío, lo informamos, sino realizamos la búsqueda
if(empty($buscar))
{
echo "No se ha ingresado una cadena a buscar";
}else{
// Conexión a la base de datos y seleccion de registros
$con=mysql_connect("localhost","root","");
$sql = "SELECT * FROM canales cn inner join estatus es on es.id_estatus=cn.id_estatus
WHERE cn.id_canal like'%".$buscar[0]."%' and es.nombre_estatus like '%".$buscar[1]."%' and DESCRIPCION_CANAL like '%".$buscar[2]."%' ORDER BY cn.ID_CANAL DESC";

mysql_select_db("db_asistencia", $con);
//}
$result = mysql_query($sql, $con);

// Tomamos el total de los resultados
$total = mysql_num_rows($result);

?>
</p>

<?php
require('countbdd.php');
//echo $men;
//$archivo = "cont_visitasC.txt";
//$contador222 = 0;

//$fp = fopen($archivo,"r");
//$contador222 = fgets($fp, 26);
//fclose($fp);

//++$contador222;

//$fp = fopen($archivo,"w+");
//fwrite($fp, $contador222, 26);
//fclose($fp);

//echo "Esta página fue visitada $contador222 veces";

?>
<p>Ultima fecha de ingreso :
<?
//FECHA ANTERIOR
//$id = mysql_query("select count(id) from contador", $con);
$query="select * from contador where id=(select count(id) from contador)-1";
// $array=mysql_fetch_row('fecha');
mysql_select_db("db_asistencia", $con);
$result2= mysql_query($query, $con);
$row2 = mysql_fetch_array($result2);

$fe= $row2['fecha'];
$ho= $row2['hora'];
echo $fe;
echo " a las ".$ho;
// echo ($id-1);




?>


<table width="968" border="1">
<tr>
<th width="56" scope="col">ID&nbsp;</th>
<th width="160" scope="col">NOMBRE&nbsp;</th>
<th width="245" scope="col">DESCRIPCION&nbsp;</th>
<th width="129" scope="col">F.CREACION&nbsp;</th>
<th width="122" scope="col">F.HABILITACION&nbsp;</th>
<th width="139" scope="col">F.DESHABILITACION&nbsp;</th>
</tr>
<?
//<th width="69" scope="col">ESTATUS&nbsp;</th>

// Imprimimos los resultados
if ($row = mysql_fetch_array($result)){
echo "Resultados para: <b>".$buscar[0]."</b>";
echo " <b>".$buscar[1]."</b>";
echo " <b>".$buscar[2]."</b>";
do {
?>


<form id="form1" name="form1" method="post" action="">

</form>
<!--cabecera -->
<tr>
<td> <? echo $row['ID_CANAL']; ?>&nbsp;</td>

<td> <? echo $row['NOMBRE_CANAL']; ?>&nbsp;</td>
<td> <? echo $row['DESCRIPCION_CANAL']; ?>&nbsp;</td>
<td> <? echo $row['FECHA_CREACION_CANAL']; ?>&nbsp;</td>
<td> <? echo $row['FECHA_HABILITACION_CANAL']; ?>&nbsp;</td>
<td><? echo $row['FECHA_DESHABILITACION_CANAL']; ?>&nbsp;</td>
</tr>



<p>


<?
//<td> <? echo $row['ESTATUS'];


} while ($row = mysql_fetch_array($result));
echo "<p>Resultados:". $total."</p>";
} else {
// En caso de no encontrar resultados
echo "No se encontraron resultados para: <b>".$total."</b>";
}
}
?>
</table>


<center>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
if (window.print) {
document.write('<form> '+'<input type=button name=print value="Imprimir" ' + 'onClick="javascript:window.print()"><\/form>');
}
</script>
<a href="FRMexportar_excel.php?tabla=canales&data=<?p hp echo $buscar; ?>" target="_blank">Exportar a Excel</a>
</center>

<?
}

?>


</body>
</html>