Hola
Miren lo que estoy haciendo es una pagina dinamica de soccer en la que el usuario pueda buscar por medio de dos campos a los jugadores, el primer campo de busqueda es un menu/select que contiene las posiciones de los jugadores y el otro es por medio del nombre.
Hasta aqui funciona, por que si busca y muestra resultados, el problema viene cuando no se selecciona ninguna posicion o no se escribe ningun nombre y se oprime el boton buscar, ya que arroja un resultado y es el primer registro de la base de datos.
Lo que intento hacer es que:
1.- Sino se ha seleccionado ninguna posicion o se ha escrito un nombre pues que no muestre nada.
2.- Que me muestre un mensaje diciendo no se ha seleccionado nada o no se ha encontrado ningun registro.
Ya le trate de agregar este codigo que vi:
<?php if (array_key_exists('busqueda1', $_GET) && $totalRows_mostrar_datos == 0){?><span style="color: #F00">No se encontraron datos</span><?php } //Este pedazo de codigo sirve para mostrar un mensaje de que no se encontraron resultados?>
pero no pasa nada
Espero que me puedan ayudar. Les dejo mi codigo
Código:
<?php require_once('Connections/bd_entrenamiento.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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_mostrar_datos = "-1";
if (isset($_GET['busqueda1'])) {
$colname_mostrar_datos = $_GET['busqueda1'];
}
$colname2_mostrar_datos = "-1";
if (isset($_GET['busqueda2'])) {
$colname2_mostrar_datos = $_GET['busqueda2'];
}
mysql_select_db($database_bd_entrenamiento, $bd_entrenamiento);
$query_mostrar_datos = sprintf("SELECT * FROM datos_jugador WHERE posicion = %s OR nombre LIKE %s", GetSQLValueString($colname_mostrar_datos, "text"),GetSQLValueString("%" . $colname2_mostrar_datos . "%", "text"));
$mostrar_datos = mysql_query($query_mostrar_datos, $bd_entrenamiento) or die(mysql_error());
$row_mostrar_datos = mysql_fetch_assoc($mostrar_datos);
$totalRows_mostrar_datos = mysql_num_rows($mostrar_datos);
?>
<!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>Pagina de Futbol</title>
<!--Css Efectos-->
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style>
body {
background-image: url(imagenes/atras.jpg);
background-attachment: fixed;
background-position: top right;
background-repeat: repeat;
}
</style>
<style>
@font-face {
font-family: 'space';
src: url('fuentes/space.ttf') format('truetype');
}
</style>
<style>
#contenedor {
position:absolute;
width:1000px;
height:600px;
z-index:1;
top: 25px;
left: 50%;
margin-left: -500px;
background-color: #FFFFFF;
}
#titulo {
position:absolute;
width:600px;
height:60px;
z-index:1;
left: 50%;
top: 40px;
margin-left: -300px;
text-align:center;
font: 60px "Urban", New York, serif;
color: #06F;
}
#buscar {
position:absolute;
width:960px;
height:55px;
z-index:2;
left: 22px;
top: 122px;
text-align:center;
font: 20px "Urban", New York, serif;
}
#resultados {
position:absolute;
width:783px;
height:347px;
z-index:3;
left: 106px;
top: 192px;
}
</style>
<style>
.Camisa{
font-family: 'sports';
font-size:45px;
text-align:center;
border:0px;
color: #19070B;
background-color: transparent;
}
</style>
</head>
<body>
<div class="Aquare" id="contenedor">
<div class="Shadow" id="titulo">Pagina de Futbol</div>
<div id="buscar">
<form id="form1_buscar" name="form1_buscar" method="GET" action="administracion_jugadores.php">
<p>Seleccione la posicion:
<label>
<select name="busqueda1" class="MenuSelect" id="busqueda1">
<option selected="selected">POSICION</option>
<option value="PORTERO">PORTERO</option>
<option value="DEFENSA">DEFENSA</option>
<option value="MEDIO">MEDIO</option>
<option value="DELANTERO">DELANTERO</option>
</select>
</label>
o escriba el nombre:
<label>
<input name="busqueda2" type="text" class="CampoDeTexto" id="busqueda2" size="20" VALUE= "<?php if (isset($_GET['busqueda2'])) echo $_GET['busqueda2'];?>"/>
</label>
<label>
<input name="enviar" type="submit" class="BotonAzul" id="enviar" value="BUSCAR" />
</label>
</form>
<?php if (array_key_exists('busqueda1', $_GET) && $totalRows_mostrar_datos == 0){?><span style="color: #F00">No se encontraron datos</span><?php } //Este pedazo de codigo sirve para mostrar un mensaje de que no se encontraron resultados?>
</div>
<div id="resultados">
<form id="datos" name="datos" method="post" action="">
<table width="780" border="1" style="font-family: 'rexlia'; font-size: 20px;">
<tr>
<td height="72" colspan="3" bgcolor="#CCCCCC" style="font-size: 30px; text-align: center;"><?php echo $row_mostrar_datos['nombre']; ?> <?php echo $row_mostrar_datos['ap_pat']; ?> <?php echo $row_mostrar_datos['ap_mat']; ?></td>
</tr>
<tr>
<td width="281" rowspan="6" style="text-align: center;"><img src="imagenes/imagenes_jugadores/<?php echo $row_mostrar_datos['imagen']; ?>" width="185" height="185" /></td>
<td width="110" rowspan="4" background="imagenes/jersey-chica.png" align="center" background-repeat:"no-repeat"><label>
<input name="nom" type="text" class="Camisa" id="nom" value="<?php echo $row_mostrar_datos['numero']; ?>" size="2" />
</label></td>
<td width="367"><?php echo $row_mostrar_datos['edad']; ?> años - <?php echo $row_mostrar_datos['fecha_nac']; ?></td>
</tr>
<tr>
<td ><?php echo $row_mostrar_datos['altura']; ?> m.</td>
</tr>
<tr>
<td><?php echo $row_mostrar_datos['peso']; ?> kg.</td>
</tr>
<tr>
<td height="26">Posicion: <?php echo $row_mostrar_datos['posicion']; ?></td>
</tr>
<tr>
<td colspan="2">Apodo: <?php echo $row_mostrar_datos['apodo']; ?></td>
</tr>
<tr>
<td colspan="2">Habilidad: <?php echo $row_mostrar_datos['habilidad']; ?></td>
</tr>
<tr>
<td style="text-align: center;">Pais: <?php echo $row_mostrar_datos['nacionalidad']; ?></td>
<td colspan="2"><p>Comentarios: </p>
<p><?php echo $row_mostrar_datos['comentarios']; ?></p></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($mostrar_datos);
?>