Jump to content

[SOLVED] Search Form Variable URL


me1000

Recommended Posts

ok I have my search code, but I want to imbed it inside of one index page,

 

My problem is that when i search for something it takes it back to the index page, and not the search results, however the URL after the search is

 

?cmd=search&words=whateverimsearchingfor&mode=normal

but since it isnt including the search.php page inside the index page it only gives me my default index page

 

the URL after you hit search should be

?type=html&page=search&cmd=search&words=whateverimsearchingfor&mode=normal

the

?type=html&page=search

must be there to show the search form,

 

in my code i dont know where to change it so the URL reflects the change,

 

here is my code, for the whole search

 

 

 

// Create the search function:

function searchForm()
{
  // Re-usable form
  
  // variable setup for the form.
  $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
  $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );
  $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );
  
  echo '<form method="get" action="http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search">';
  echo '<input type="hidden" name="cmd" value="search" />';
  echo 'Search for: <input type="text" style="color: #FFFFFF; border: 2px ridge #000000; background-color: #A5A5A5" name="words" value="'.$searchwords.'" /> ';
  echo 'Mode: ';
  echo '<select style="color: #FFFFFF; border: 2px ridge #000000; background-color: #A5A5A5" name="mode">';
  echo '<option value="normal"'.$normal.'>Normal</option>';
  echo '<option value="boolean"'.$boolean.'>Boolean</option>';
  echo '</select> ';
  echo '<input type="submit" style="color: #000; border: 1px ridge #000000; background-color: #A5A5A5" value="Search" />';
  echo '</form>';
}


// Create the navigation switch
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');

switch($cmd)
{
  default:
    echo '<h2>Search site!</h2>';
    searchForm();
  
  break;
  
  
  case "search":
    searchForm();
    echo '<h3>Search Results:</h3><br />';
    
    $searchstring = mysql_escape_string($_GET['words']);
    switch($_GET['mode'])
    {
      case "normal":
        $sql = "SELECT ID, PAGE_TITLE, KEYWORDS, 
               MATCH(KEYWORDS) 
               AGAINST ('$searchstring') AS score FROM site_PAGES 
               WHERE MATCH(KEYWORDS) 
               AGAINST ('$searchstring') ORDER BY score DESC";
      break;
      
      case "boolean":
        $sql = "SELECT ID, PAGE_TITLE, KEYWORDS, 
               MATCH(KEYWORDS) 
               AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM site_PAGES 
               WHERE MATCH(KEYWORDS) 
               AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
      break;
    } 
    
    // echo $sql;
    
    $result = mysql_query($sql) or die (mysql_error());
    
    while($row = mysql_fetch_object($result))
    {
      echo '<font size="2" face="Arial"><strong>Title: <a href="http://www.site.com/index.php?page_id='.$row->ID.'">'.$row->PAGE_TITLE.'</a></strong><br />';
      echo 'Score: '. number_format($row->score, 1);
      echo '<br>Keywords:</font> <font size="1">'.stripslashes(htmlspecialchars($row->KEYWORDS))."</font>";
      echo '<hr size="1" />';
    }
  break;
}

 

 

Any ideas??

 

Thanks

Link to comment
Share on other sites

ok well i dont think what i originally wanted to do is possible,

 

however here is my work around,

 

 

if ($cmd="search" AND $before == "") {
header( 'Location: http://www.site.com/3rd_ani_template/V2/template.php?type=html&page=search&before=yes&cmd=search&words='.$words.'&mode='.$mode.'&submit='.$submit ) ;
}else{

}

 

however, I have no idea how to add mutable conditions to an if statement, without writing an if statement inside of another!

 

can someone tell me how?? lol

 

 

 

nevermind

 

for the record it is if lala && lala

then you are singing! lol

 

it works now...

 

 

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.