Foros del Web » Programando para Internet » PHP »

Podrian ayudarme a resaltar de color los datos de busqueda

Estas en el tema de Podrian ayudarme a resaltar de color los datos de busqueda en el foro de PHP en Foros del Web. Hola de nuevo, podrian ayudarme, lo primero es que muestro una tabla en donde realizare una búsqueda de alguna palabra o dato de mi base ...
  #1 (permalink)  
Antiguo 05/10/2011, 15:42
 
Fecha de Ingreso: octubre-2011
Mensajes: 5
Antigüedad: 12 años, 6 meses
Puntos: 0
Pregunta Podrian ayudarme a resaltar de color los datos de busqueda

Hola de nuevo, podrian ayudarme, lo primero es que muestro una tabla en donde realizare una búsqueda de alguna palabra o dato de mi base de datos y como resultado colorea lo que encontro segun la busqueda, pero lo que ahora quiero hacer es que lo que encontro de resultado lo deje sin color (en blanco osea solo con el texto) y lo que no corresponde a la busqueda lo ponga de un color,este es mi codigo:

<?php
include("conec.php");
error_reporting(E_PARSE);

$busqueda=$_POST["Busqueda"];

if ($busqueda!="")
{
$lsQryB="select idEmpresa from (Select idEmpresa,NomEmpresa,NomContacto,ApellidosContacto ,PuestoContacto from visionaria.OracleCuliacan where NomContacto<>'' Limit 10) as Tabla where idEmpresa like '%$busqueda%' or NomContacto like '%$busqueda%'";
$resultado2=mysql_query($lsQryB) or die(mysql_error());
$conteo=mysql_num_rows($resultado2);
}

$lsQry="Select idEmpresa,NomEmpresa,NomContacto,ApellidosContacto ,PuestoContacto from visionaria.OracleCuliacan where NomContacto<>'' Limit 10";
$resultado=mysql_query($lsQry) or die(mysql_error());


?>
<!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>Untitled Document</title>
<style type="text/css">
div.centrado{
text-align: center;
}
div.centrado table {
margin: 0 auto;
text-align: left;
}
</style>
<script language="javascript">

function Busca()
{
document.form1.action="in.php";
document.form1.submit();
}

</script>
</head>
<body>
<div class="centrado">
<table width="732" height="149" border="0">
<tr>
<td width="55">&nbsp;</td>
<td width="592" style="text-align:center"><form id="form1" name="form1" method="post" action="#">
Busqueda
<input type="text" name="Busqueda" id="Busqueda" />
<input type="button" name="Enviar" id="Enviar" value="Buscar" onclick="Busca()" />
</form></td>
<td width="63">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td style="text-align:center">
<?php

$i=0;

if($conteo!=0)
{
while($arrBusqueda=mysql_fetch_array($resultado2))
{
$arrValores[$i]=$arrBusqueda["idEmpresa"];
$i++;
}
}
else
echo "No existen Empresas";





echo "<table border=\"1\">";
echo "<tr>";
echo "<td>Id Cliente</td>";
echo "<td>Empresa</td>";
echo "<td>Nombre</td>";
echo "<td>Apellidos</td>";
echo "<td>Puesto</td>";
echo "</tr>";

while($arrRegistros=mysql_fetch_array($resultado))
{


for ($j=0;$j<=$i;$j++)
{
if ($arrRegistros["idEmpresa"]==$arrValores[$j])
{
echo "<tr style=\"background-color:#653\">";
$m=1;
}
else
$m=0;
}

if($m=0)
echo "<tr>";
echo "<td>".$arrRegistros["idEmpresa"]."</td>";
echo "<td>".$arrRegistros["NomEmpresa"]."</td>";
echo "<td>".$arrRegistros["NomContacto"]."</td>";
echo "<td>".$arrRegistros["ApellidosContacto"]."</td>";
echo "<td>".$arrRegistros["PuestoContacto"]."</td>";
echo "</tr>";


}
echo "</table>";
?>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</div>
</body>
</html>


Alguna idea???
De antemano gracias
  #2 (permalink)  
Antiguo 05/10/2011, 17:51
Avatar de mcun  
Fecha de Ingreso: octubre-2010
Ubicación: tras la pantalla
Mensajes: 466
Antigüedad: 13 años, 6 meses
Puntos: 55
Respuesta: Podrian ayudarme a resaltar de color los datos de busqueda

pon el código entre etiquetas de código que sino es muy difícil de leerlo ... a mi a esta altura del día/noche me duelen los ojos :P
  #3 (permalink)  
Antiguo 06/10/2011, 12:00
 
Fecha de Ingreso: octubre-2011
Mensajes: 5
Antigüedad: 12 años, 6 meses
Puntos: 0
Respuesta: Podrian ayudarme a resaltar de color los datos de busqueda

Cita:
Iniciado por mcun Ver Mensaje
pon el código entre etiquetas de código que sino es muy difícil de leerlo ... a mi a esta altura del día/noche me duelen los ojos :P
no se como hacerlo?
  #4 (permalink)  
Antiguo 06/10/2011, 12:02
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 8 meses
Puntos: 194
Respuesta: Podrian ayudarme a resaltar de color los datos de busqueda

PHP CODIGO /PHP

tanto PHP como /PHP entre corchetes
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #5 (permalink)  
Antiguo 06/10/2011, 12:39
Avatar de andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: Podrian ayudarme a resaltar de color los datos de busqueda

A ver si así te ayudan

Código PHP:
Ver original
  1. <?php
  2. include ("conec.php");
  3. error_reporting(E_PARSE);
  4.  
  5. $busqueda = $_POST["Busqueda"];
  6.  
  7. if ($busqueda != "") {
  8.     $lsQryB = "select idEmpresa from (Select idEmpresa,NomEmpresa,NomContacto,ApellidosContacto ,PuestoContacto from visionaria.OracleCuliacan where NomContacto<>'' Limit 10) as Tabla where idEmpresa like '%$busqueda%' or NomContacto like '%$busqueda%'";
  9.     $resultado2 = mysql_query($lsQryB) or die(mysql_error());
  10.     $conteo = mysql_num_rows($resultado2);
  11. }
  12.  
  13. $lsQry = "Select idEmpresa,NomEmpresa,NomContacto,ApellidosContacto ,PuestoContacto from visionaria.OracleCuliacan where NomContacto<>'' Limit 10";
  14. $resultado = mysql_query($lsQry) or die(mysql_error());
  15.  
  16. ?>
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  18. <html xmlns="http://www.w3.org/1999/xhtml">
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <title>Untitled Document</title>
  22. <style type="text/css">
  23. div.centrado {
  24.     text-align: center;
  25. }
  26.  
  27. div.centrado table {
  28.     margin: 0 auto;
  29.     text-align: left;
  30. }
  31. </style>
  32. <script language="javascript">
  33.  
  34. function Busca()
  35. {
  36. document.form1.action="in.php";
  37. document.form1.submit();
  38. }
  39.  
  40. </script>
  41. </head>
  42. <body>
  43. <div class="centrado">
  44. <table width="732" height="149" border="0">
  45.     <tr>
  46.         <td width="55">&nbsp;</td>
  47.         <td width="592" style="text-align: center">
  48.         <form id="form1" name="form1" method="post" action="#">Busqueda <input
  49.             type="text" name="Busqueda" id="Busqueda" /> <input type="button"
  50.             name="Enviar" id="Enviar" value="Buscar" onclick="Busca()" /></form>
  51.         </td>
  52.         <td width="63">&nbsp;</td>
  53.     </tr>
  54.     <tr>
  55.         <td>&nbsp;</td>
  56.         <td style="text-align: center">
  57. <?php
  58.  
  59. $i = 0;
  60.  
  61. if ($conteo != 0) {
  62.     while ($arrBusqueda = mysql_fetch_array($resultado2)) {
  63.         $arrValores[$i] = $arrBusqueda["idEmpresa"];
  64.         $i++;
  65.     }
  66. } else
  67.     echo "No existen Empresas";
  68.  
  69. echo "<table border=\"1\">";
  70. echo "<tr>";
  71. echo "<td>Id Cliente</td>";
  72. echo "<td>Empresa</td>";
  73. echo "<td>Nombre</td>";
  74. echo "<td>Apellidos</td>";
  75. echo "<td>Puesto</td>";
  76. echo "</tr>";
  77.  
  78. while ($arrRegistros = mysql_fetch_array($resultado)) {
  79.    
  80.     for ($j = 0; $j <= $i; $j++) {
  81.         if ($arrRegistros["idEmpresa"] == $arrValores[$j]) {
  82.             echo "<tr style=\"background-color:#653\">";
  83.             $m = 1;
  84.         } else
  85.             $m = 0;
  86.     }
  87.    
  88.     if ($m = 0)
  89.         echo "<tr>";
  90.     echo "<td>" . $arrRegistros["idEmpresa"] . "</td>";
  91.     echo "<td>" . $arrRegistros["NomEmpresa"] . "</td>";
  92.     echo "<td>" . $arrRegistros["NomContacto"] . "</td>";
  93.     echo "<td>" . $arrRegistros["ApellidosContacto"] . "</td>";
  94.     echo "<td>" . $arrRegistros["PuestoContacto"] . "</td>";
  95.     echo "</tr>";
  96.  
  97. }
  98. echo "</table>";
  99. ?>
  100. </td>
  101.         <td>&nbsp;</td>
  102.     </tr>
  103.     <tr>
  104.         <td>&nbsp;</td>
  105.         <td>&nbsp;</td>
  106.         <td>&nbsp;</td>
  107.     </tr>
  108. </table>
  109. </div>
  110. </body>
  111. </html>
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP
  #6 (permalink)  
Antiguo 06/10/2011, 13:09
Avatar de h2swider  
Fecha de Ingreso: julio-2007
Ubicación: Ciudad de Buenos Aires
Mensajes: 932
Antigüedad: 16 años, 8 meses
Puntos: 194
Respuesta: Podrian ayudarme a resaltar de color los datos de busqueda

Si ahora si! jaja

Lo que haría para resolverlo rápido seria, en el momento de hacer una busqueda, agregar una linea de css, dandole el color que tu quieras a todo el texto del

por ejemplo body{color:green}

Y coloreas el resultado, del color normal que utilizas siempre
__________________
Codifica siempre como si la persona que finalmente mantedra tu código sea un psicópata violento que sabe donde vives
  #7 (permalink)  
Antiguo 06/10/2011, 13:28
 
Fecha de Ingreso: octubre-2011
Mensajes: 5
Antigüedad: 12 años, 6 meses
Puntos: 0
Respuesta: Podrian ayudarme a resaltar de color los datos de busqueda

Cita:
Iniciado por andresdzphp Ver Mensaje
A ver si así te ayudan

Código PHP:
Ver original
  1. <?php
  2. include ("conec.php");
  3. error_reporting(E_PARSE);
  4.  
  5. $busqueda = $_POST["Busqueda"];
  6.  
  7. if ($busqueda != "") {
  8.     $lsQryB = "select idEmpresa from (Select idEmpresa,NomEmpresa,NomContacto,ApellidosContacto ,PuestoContacto from visionaria.OracleCuliacan where NomContacto<>'' Limit 10) as Tabla where idEmpresa like '%$busqueda%' or NomContacto like '%$busqueda%'";
  9.     $resultado2 = mysql_query($lsQryB) or die(mysql_error());
  10.     $conteo = mysql_num_rows($resultado2);
  11. }
  12.  
  13. $lsQry = "Select idEmpresa,NomEmpresa,NomContacto,ApellidosContacto ,PuestoContacto from visionaria.OracleCuliacan where NomContacto<>'' Limit 10";
  14. $resultado = mysql_query($lsQry) or die(mysql_error());
  15.  
  16. ?>
  17. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  18. <html xmlns="http://www.w3.org/1999/xhtml">
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <title>Untitled Document</title>
  22. <style type="text/css">
  23. div.centrado {
  24.     text-align: center;
  25. }
  26.  
  27. div.centrado table {
  28.     margin: 0 auto;
  29.     text-align: left;
  30. }
  31. </style>
  32. <script language="javascript">
  33.  
  34. function Busca()
  35. {
  36. document.form1.action="in.php";
  37. document.form1.submit();
  38. }
  39.  
  40. </script>
  41. </head>
  42. <body>
  43. <div class="centrado">
  44. <table width="732" height="149" border="0">
  45.     <tr>
  46.         <td width="55">&nbsp;</td>
  47.         <td width="592" style="text-align: center">
  48.         <form id="form1" name="form1" method="post" action="#">Busqueda <input
  49.             type="text" name="Busqueda" id="Busqueda" /> <input type="button"
  50.             name="Enviar" id="Enviar" value="Buscar" onclick="Busca()" /></form>
  51.         </td>
  52.         <td width="63">&nbsp;</td>
  53.     </tr>
  54.     <tr>
  55.         <td>&nbsp;</td>
  56.         <td style="text-align: center">
  57. <?php
  58.  
  59. $i = 0;
  60.  
  61. if ($conteo != 0) {
  62.     while ($arrBusqueda = mysql_fetch_array($resultado2)) {
  63.         $arrValores[$i] = $arrBusqueda["idEmpresa"];
  64.         $i++;
  65.     }
  66. } else
  67.     echo "No existen Empresas";
  68.  
  69. echo "<table border=\"1\">";
  70. echo "<tr>";
  71. echo "<td>Id Cliente</td>";
  72. echo "<td>Empresa</td>";
  73. echo "<td>Nombre</td>";
  74. echo "<td>Apellidos</td>";
  75. echo "<td>Puesto</td>";
  76. echo "</tr>";
  77.  
  78. while ($arrRegistros = mysql_fetch_array($resultado)) {
  79.    
  80.     for ($j = 0; $j <= $i; $j++) {
  81.         if ($arrRegistros["idEmpresa"] == $arrValores[$j]) {
  82.             echo "<tr style=\"background-color:#653\">";
  83.             $m = 1;
  84.         } else
  85.             $m = 0;
  86.     }
  87.    
  88.     if ($m = 0)
  89.         echo "<tr>";
  90.     echo "<td>" . $arrRegistros["idEmpresa"] . "</td>";
  91.     echo "<td>" . $arrRegistros["NomEmpresa"] . "</td>";
  92.     echo "<td>" . $arrRegistros["NomContacto"] . "</td>";
  93.     echo "<td>" . $arrRegistros["ApellidosContacto"] . "</td>";
  94.     echo "<td>" . $arrRegistros["PuestoContacto"] . "</td>";
  95.     echo "</tr>";
  96.  
  97. }
  98. echo "</table>";
  99. ?>
  100. </td>
  101.         <td>&nbsp;</td>
  102.     </tr>
  103.     <tr>
  104.         <td>&nbsp;</td>
  105.         <td>&nbsp;</td>
  106.         <td>&nbsp;</td>
  107.     </tr>
  108. </table>
  109. </div>
  110. </body>
  111. </html>
jejejej muchas gracias!!

Etiquetas: color, html, mysql, registro, resaltar, tabla, busquedas
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 10:09.