search two table with one form field

Discussion in 'General PHP' started by cyclops4real007, Apr 6, 2017.

  1. cyclops4real007

    cyclops4real007 Member

    Joined:
    Jan 25, 2017
    Messages:
    147
    Likes Received:
    6
    hi i have this code and i want to include a second table to it how do i go about it

    if (isset($_SESSION['advs']) && is_array($_SESSION['advs']))
    {
    $searching = true;
    if (!empty($_SESSION['advs']['title']))
    {
    $wher .= '(';
    if (isset($_SESSION['advs']['desc']))
    {
    $wher .= "(au.description LIKE :likedescription) OR ";
    $asparams[] = array(':likedescription', '%' . $system->cleanvars($_SESSION['advs']['title']) . '%', 'str');
    }
    $wher .= "(au.title like :liketitle OR au.id = :idtitle)) AND ";
    $asparams[] = array(':idtitle', intval($_SESSION['advs']['title']), 'int');
    $asparams[] = array(':liketitle', '%' . $system->cleanvars($_SESSION['advs']['title']) . '%', 'str');
    }
    want to include subtitle as the second query so i can search both title and subtitle on one form field, need assistance thanks
     
  2. BabyDunk

    BabyDunk Active Member

    Joined:
    Feb 26, 2017
    Messages:
    279
    Likes Received:
    22
    this should do the job

    replace this
    PHP:
    $wher .= "(au.title like :liketitle OR au.id = :idtitle)) AND ";
            
    $asparams[] = array(':idtitle'$_SESSION['advs']['title'], 'int');
            
    $asparams[] = array(':liketitle''%' $system->cleanvars($_SESSION['advs']['title']) . '%''str');
    with this
    PHP:
    $wher .= "(au.title like :liketitle OR au.subtitle like :likesubtitle OR au.id = :idtitle)) AND ";
            
    $asparams[] = array(':idtitle'$_SESSION['advs']['title'], 'int');
            
    $asparams[] = array(':liketitle''%' $system->cleanvars($_SESSION['advs']['title']) . '%''str');
            
    $asparams[] = array(':likesubtitle''%' $system->cleanvars($_SESSION['advs']['title']) . '%''str');
     
    Last edited: Apr 9, 2017
    cyclops4real007 likes this.
  3. skyhigh

    skyhigh Member

    Joined:
    Sep 28, 2010
    Messages:
    446
    Likes Received:
    8

Share This Page