Jump to content

Plase help with search function


lingo5

Recommended Posts

Hi,

I am trying to build a search function and so far I have it working with just one DB field but I need it to search for different fields.

 

This is my search form:

 

<form action="t_articulo_Results.php" method="get" name="SearchForm" id="SearchForm">
          <label>
            <input type="text" name="S_articulo_esp" id="S_articulo_esp" value="search" size="30" />
             <input type="hidden" name="Search" id="Search" value="Buscar" />
            </label>
          </form>

 

where the field "S_articulo_esp" is a text field to enter the search criteria.

 

This is the code on my results page inclung query:

 

<?php 

$MySearch_DefaultWhere = "";
if (!session_id()) session_start();
if ((isset($_GET["Search"]) && $_GET["Search"] != "")) {
  $MySearch = new FilterDef;
  $MySearch->initializeQueryBuilder("MYSQL","1");
  //keyword array declarations

  //comparison list additions
  $MySearch->addComparisonFromEdit("company_name","S_articulo_esp","AND","Includes",0);

  //save the query in a session variable
  if (1 == 1) {
    $_SESSION["MySearch_t_articulo_Results"]=$MySearch->whereClause;
  }
}
else     {
  $MySearch = new FilterDef;
  $MySearch->initializeQueryBuilder("MYSQL","1");
  //get the filter definition from a session variable
  if (1 == 1)     {
    if (isset($_SESSION["MySearch_t_articulo_Results"]) && $_SESSION["MySearch_t_articulo_Results"] != "")     {
      $MySearch->whereClause = $_SESSION["MySearch_t_articulo_Results"];
    }
    else     {
      $MySearch->whereClause = $MySearch_DefaultWhere;
    }
  }
  else     {
    $MySearch->whereClause = $MySearch_DefaultWhere;
  }
}
$MySearch->whereClause = str_replace("\\''", "''", $MySearch->whereClause);
$MySearchwhereClause = '';
?>


<?php
$maxRows_RecordSett_articulo = 10;
$pageNum_RecordSett_articulo = 0;
if (isset($_GET['pageNum_RecordSett_articulo'])) {
  $pageNum_RecordSett_articulo = $_GET['pageNum_RecordSett_articulo'];
}
$startRow_RecordSett_articulo = $pageNum_RecordSett_articulo * $maxRows_RecordSett_articulo;

mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_RecordSett_articulo = "SELECT id_cliente, company_name, cliente_calle, cliente_numero, cliente_local, cliente_poblacion, cliente_cp, cliente_pais, cliente_tel, cliente_fax, cliente_movil, cliente_personadecontacto, cliente_email, cliente_web FROM t_clientes ORDER BY company_name ASC";
setQueryBuilderSource($query_RecordSett_articulo,$WADbSearch1,false);
$query_limit_RecordSett_articulo = sprintf("%s LIMIT %d, %d", $query_RecordSett_articulo, $startRow_RecordSett_articulo, $maxRows_RecordSett_articulo);
$RecordSett_articulo = mysql_query($query_limit_RecordSett_articulo, $MySQLconnect) or die(mysql_error());
$row_RecordSett_articulo = mysql_fetch_assoc($RecordSett_articulo);

if (isset($_GET['totalRows_RecordSett_articulo'])) {
  $totalRows_RecordSett_articulo = $_GET['totalRows_RecordSett_articulo'];
} else {
  $all_RecordSett_articulo = mysql_query($query_RecordSett_articulo);
  $totalRows_RecordSett_articulo = mysql_num_rows($all_RecordSett_articulo);
}
$totalPages_RecordSett_articulo = ceil($totalRows_RecordSett_articulo/$maxRows_RecordSett_articulo)-1;
?>

 

please note this line

 

$MySearch->addComparisonFromEdit("company_name","S_articulo_esp","AND","Includes",0);//comparison list additions

 

because here is where I am getting confused . How can I add more fields to it?

 

Thanks

Link to comment
Share on other sites

There's no way for us to answer your question from the code provided. You are apparently using a custom class to drive a lot of your functionality. addComparisonFromEdit() is a method within that class. I have no idea what that function does, what it returns or what variations in parameters it can accept. If you wrote that class then you should know that info. If you did not write the class then contact the author for help.

Link to comment
Share on other sites

Thanks mjdmato. I did not write that class but thi is what it does:

 

  
//add a comparison argument from an edit box
  function addComparisonFromEdit($Column,$EditName,$Logical,$Comparison,$FieldType) {
    if (isset($_GET[$EditName])) {
      $theValue = $_GET[$EditName];
    }
    elseif (isset($_POST[$EditName])) {
      $theValue = $_POST[$EditName];
    }
    if (isset($theValue) && $theValue != "undefined" && $theValue != "") {
      $this->addComparison($Column,$theValue,$Logical,$Comparison,$FieldType);
    }
  }

Link to comment
Share on other sites

Right, and that class then calls another class "addComparison()". Which could lead to another class and/or will reference properties that are defined elsewhere. Someone would likely need to review the entire class to see if it is even possible to use the current code to do a search against multiple columns or if the class would need to be modified.

 

The description for this forum is (emphasis added):

Do you need help with some code you wrote? Ask here! We'll get you the answers!

 

You should really contact the author of the class you are using.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.