Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/02/2011, 21:04
Avatar de camilo1012
camilo1012
 
Fecha de Ingreso: febrero-2011
Mensajes: 46
Antigüedad: 13 años, 2 meses
Puntos: 1
Respuesta: seleccionar todos en uno

No se si te sirva de mucho pero lo puedes leer por id o si no puedes hacer un buscador en PHP, de todas formas te dejo los dos códigos, el de la lectura y el buscador.

Lectura:
Código:
Código HTML:
[PHP]<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>lectura.php</title>
</head>

<body>
<h1><div align="center">Lectura de la tabla</div></h1>
<br>
<br>
<?
mysql_connect("127.0.0.1","root","pass");
$result=mysql_db_query("//base","select * from //tabla");
?>
<table align="center">
<tr>
<th>id</th>
<th>link</th>
</tr>
<?
while ($row=mysql_fetch_array($result))
{
	echo '<tr><td>'.$row["id"].'</td>';
	echo '<td>'.$row["link"].'</td></tr>';
}
mysql_free_result($result)
?>
</table>
</body>
</html>[/PHP]

Buscador:
Código:
Código HTML:
[PHP]<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Documento sin título</title>
</head>

<body>
<h1><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Buscador</a></h1>
<form name="buscar" action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
Buscar: <input type="text" size="50″ value="<?php echo $_GET['frase']; ?>" name="frase" />
<input type="submit" name="buscar" value="Buscar" />
</form>

<?php
// conectar al servidor
$server_link = mysql_connect("127.0.0.1", "root", "pass");
if(!$server_link){
    die("Fall&oacute; la Conexi&oacute;n ". mysql_error());
}
// seleccionamos la base de datos
$db_selected = mysql_select_db("//base", $server_link);
if(!$db_selected){
    die("No se pudo seleccionar la Base de Datos ". mysql_error());
}
// varificamos que el formulario halla sido enviado
if(isset($_GET['buscar']) && $_GET['buscar'] == 'Buscar'){
    $frase = addslashes($_GET['frase']);
    // hacemos la consulta de busqueda
    $sqlBuscar = mysql_query("SELECT noticiaTitulo, noticiaNoticia,
                              MATCH (noticiaTitulo, noticiaNoticia)
                              AGAINST ('$frase' IN BOOLEAN MODE) AS coincidencias
                              FROM noticias
                              WHERE MATCH (noticiaTitulo, noticiaNoticia)
                              AGAINST ('$frase' IN BOOLEAN MODE)
                              ORDER BY coincidencias DESC", $server_link)
                              or die(mysql_error());                              
    $totalRows = mysql_num_rows($sqlBuscar);
    // Enviamos un mensaje
    // indicando la cantidad de resultados ($totalRows)
    // para la frase busada ($frase)
    if(!empty($totalRows)){
        echo stripslashes("<p>Su b&uacute;squeda arroj&oacute; <strong>$totalRows</strong> resultados para <strong>$frase</strong></p>");        
        // mostramos los resultados
        while($row = mysql_fetch_array($sqlBuscar)){
            echo "<strong><a href='#'>$row[noticiaTitulo]</a>:</strong> <em>Coincidencias: ". round($row['coincidencias']) ."</em><br />";
            echo "<p>".substr(strip_tags($row['noticiaNoticia']), 0, 255)."...</p>";
        }
    }
    // si se ha enviado vacio el formulario
    // mostramos un mensaje del tipo Oops...!
    elseif(empty($_GET['frase'])){
        echo "Debe introducir una palabra o frase.";
    }
    // si no hay resultados
    // otro mensaje del tipo Oops...!
    elseif($totalRows == 0){
        echo stripslashes("Su busqueda no arrojo resultados para <strong>$frase</strong>");
    }
}
?>

</body>
</html>[/PHP]