Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP Search of MySQL database no records found

    Hi
    I am very new to php and need some help. I have been asked by my employer to change some aspects of our website, mainly column names that appear in a table produced from a MySQL database. I have been able to do this successfully but I am having a problem with the search function for the columns with names that I have changed. I recieve the message "No records found" even when I search for a term that I know is contained in the column. The search function on our website is divided into three boxes: one drop down box for field, one drop down box for operater (ie. Contains, Starts with, Equals etc.) and one for the variable/term that you are searching for.
    The code for searching is:
    [// Action or Project
    $opt="";
    $not=false;
    $control_Action_or_Project=array();
    $control_Action_or_Project["params"] = array();
    if(@$_SESSION[$strTableName."_search"]==2)
    {
    $opt=@$_SESSION[$strTableName."_asearchopt"]["Action_or_Project"];
    $not=@$_SESSION[$strTableName."_asearchnot"]["Action_or_Project"];
    $control_Action_or_Project["params"]["value"]=@$_SESSION[$strTableName."_asearchfor"]["Action_or_Project"];
    }
    $control_Action_or_Project["func"]="xt_buildeditcontrol";
    $control_Action_or_Project["params"]["field"]="Action_or_Project";
    $control_Action_or_Project["params"]["mode"]="search";
    $xt->assignbyref("Action_or_Project_editcontrol",$control_Action_or_Project);
    $control1_Action_or_Project=$control_Action_or_Project;
    $control1_Action_or_Project["params"]["second"]=true;
    if(@$_SESSION[$strTableName."_search"]==2)
    $control1_Action_or_Project["params"]["value"]=@$_SESSION[$strTableName."_asearchfor2"]["Action_or_Project"];
    $xt->assignbyref("Action_or_Project_editcontrol1",$control1_Action_or_Project);

    $xt->assign_section("Action_or_Project_fieldblock","<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Action_or_Project\">","");
    $notbox_Action_or_Project="name=\"not_Action_or_Project\"";
    if($not)
    $notbox_Action_or_Project=" checked";
    $xt->assign("Action_or_Project_notbox",$notbox_Action_or_Project);

    // write search options
    $options="";
    $options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contains"."</option>";
    $options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equals"."</option>";
    $options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Starts with ..."."</option>";
    $options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."More than ..."."</option>";
    $options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Less than ..."."</option>";
    $options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Equal or more than ..."."</option>";
    $options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Equal or less than ..."."</option>";
    $options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Between"."</option>";
    $options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Empty"."</option>";
    $searchtype = "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Action_or_Project\" SIZE=1 onChange=\"return ShowHideControls();\">";
    $searchtype .= $options;
    $searchtype .= "</SELECT>";
    $xt->assign("searchtype_Action_or_Project",$searchtype);
    // edit format
    $editformats["Action_or_Project"]="Text field";]

    This is just a portion of the code but I believe this is where the problem lies. I know that the code is connecting the the database and to the proper tables because I can search the other columns easily. I feel like this problem is probably something simple (like _ or ") but I cannot find my mistake comparing it to other code.

    Thank you so much for any help!!
    Last edited by sdrc; 07-27-2011 at 05:08 PM.

  2. #2
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,774
    Thanks
    84
    Thanked 110 Times in 109 Posts
    First of all you should use code tags so we can better understand it. So here we go, now we can get started.

    PHP Code:
    [// Action or Project
    $opt="";
    $not=false;
    $control_Action_or_Project=array();
    $control_Action_or_Project["params"] = array();
    if(@
    $_SESSION[$strTableName."_search"]==2)
    {
    $opt=@$_SESSION[$strTableName."_asearchopt"]["Action_or_Project"];
    $not=@$_SESSION[$strTableName."_asearchnot"]["Action_or_Project"];
    $control_Action_or_Project["params"]["value"]=@$_SESSION[$strTableName."_asearchfor"]["Action_or_Project"];
    }
    $control_Action_or_Project["func"]="xt_buildeditcontrol";
    $control_Action_or_Project["params"]["field"]="Action_or_Project";
    $control_Action_or_Project["params"]["mode"]="search";
    $xt->assignbyref("Action_or_Project_editcontrol",$control_Action_or_Project);
    $control1_Action_or_Project=$control_Action_or_Project;
    $control1_Action_or_Project["params"]["second"]=true;
    if(@
    $_SESSION[$strTableName."_search"]==2)
    $control1_Action_or_Project["params"]["value"]=@$_SESSION[$strTableName."_asearchfor2"]["Action_or_Project"];
    $xt->assignbyref("Action_or_Project_editcontrol1",$control1_Action_or_Project);

    $xt->assign_section("Action_or_Project_fieldblock","<input type=\"Hidden\" name=\"asearchfield[]\" value=\"Action_or_Project\">","");
    $notbox_Action_or_Project="name=\"not_Action_or_Project\"";
    if(
    $not)
    $notbox_Action_or_Project=" checked";
    $xt->assign("Action_or_Project_notbox",$notbox_Action_or_Project);

    // write search options
    $options="";
    $options.="<OPTION VALUE=\"Contains\" ".(($opt=="Contains")?"selected":"").">"."Contains"."</option>";
    $options.="<OPTION VALUE=\"Equals\" ".(($opt=="Equals")?"selected":"").">"."Equals"."</option>";
    $options.="<OPTION VALUE=\"Starts with ...\" ".(($opt=="Starts with ...")?"selected":"").">"."Starts with ..."."</option>";
    $options.="<OPTION VALUE=\"More than ...\" ".(($opt=="More than ...")?"selected":"").">"."More than ..."."</option>";
    $options.="<OPTION VALUE=\"Less than ...\" ".(($opt=="Less than ...")?"selected":"").">"."Less than ..."."</option>";
    $options.="<OPTION VALUE=\"Equal or more than ...\" ".(($opt=="Equal or more than ...")?"selected":"").">"."Equal or more than ..."."</option>";
    $options.="<OPTION VALUE=\"Equal or less than ...\" ".(($opt=="Equal or less than ...")?"selected":"").">"."Equal or less than ..."."</option>";
    $options.="<OPTION VALUE=\"Between\" ".(($opt=="Between")?"selected":"").">"."Between"."</option>";
    $options.="<OPTION VALUE=\"Empty\" ".(($opt=="Empty")?"selected":"").">"."Empty"."</option>";
    $searchtype "<SELECT ID=\"SearchOption\" NAME=\"asearchopt_Action_or_Project\" SIZE=1 onChange=\"return ShowHideControls();\">";
    $searchtype .= $options;
    $searchtype .= "</SELECT>";
    $xt->assign("searchtype_Action_or_Project",$searchtype);
    // edit format
    $editformats["Action_or_Project"]="Text field";] 

  3. #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry about not putting the code in the correct format!


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •