ajuda php mysql (pesquisa)

HLDR7

Suspenso
criei no meu site um sistema de pesquisa, mas apenas sei fazer consultas apenas a um campo neste caso, ao campo Titulo. Como faço para procurar em Titulo e Descricao?

PHP:
<?php require_once('Connections/conAlbum.php'); ?>
<?php
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_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_Recordset1 = "-1";
if (isset($_POST['pesquisa'])) {
  $colname_Recordset1 = $_POST['pesquisa'];
}
mysql_select_db($database_conAlbum, $conAlbum);
$query_Recordset1 = sprintf("SELECT * FROM fotos WHERE Titulo LIKE %s ", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));
$Recordset1 = mysql_query($query_Recordset1, $conAlbum) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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>Documento sin t&iacute;tulo</title>
</head>

<body>
<?php do { ?>
 <table width="100" border="0" cellspacing="0" cellpadding="0">
  <tr>
   <td><a href="http://domain2051310.sites.rumonet.org/fotos/<?php echo $row_Recordset1['Foto']; ?>" rel="lightbox[large]" title="<?php echo $row_Recordset1['Titulo']; ?>  &lt;br&gt;<?php echo $row_Recordset1['Descricao']; ?> "><img src="http://domain2051310.sites.rumonet.org/fotos/mini/<?php echo $row_Recordset1['Foto']; ?>" alt="<?php echo $row_Recordset1['Titulo']; ?>" border="0"  /> </td>
  </tr>
   </table>
 <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
 
se nao for pedir muito...podias mudar a parte que é para mudar(colocar mais uma string) e apresentares aqui no topic?

é que que ,como ja disse, eu pouco sei de php.
 
Sendo assim, acho que deverias dar uma vista de olhos num bom manual de PHP :007:.

PHP:
/* adiciona a linha que se segue */
$text = GetSQLValueString("%" . $colname_Recordset1 . "%", "text");
/* altera a linha que se segue */
$query_Recordset1 = sprintf("SELECT * FROM fotos WHERE Titulo LIKE %s OR Descricao LIKE %s", $text, $text);
 
fiz um exemplo usando números:


Código:
<?php
 
//multiplos de 4
 
for($i=1;$i<11;$i++){//vai listar os números até 10
 
   if(($i % 4)!==0){//instrução que calcula o resto. se a divisão de indice fôr zero faz uma quebra de linha
       echo $i;
   }else{
       echo $i." <br />";
   } //FIM DO IF
}//FIM DO FOR
 
?>


espero que tenhas compreendido a lógica
 
Última edição:
Back
Topo