lingo5 Posted December 1, 2011 Share Posted December 1, 2011 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 1, 2011 Share Posted December 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted December 1, 2011 Author Share Posted December 1, 2011 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); } } Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 1, 2011 Share Posted December 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
lingo5 Posted December 1, 2011 Author Share Posted December 1, 2011 OK I understand. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.