Results 1 to 4 of 4
  1. #1

    * Working with Forms..

    Hi there,

    I am working on a site, where I have a search function. I am using a open source search script, phpdig for that. I wanted to know, how can set a default search words using the submit button.I mean, there on the site I have two buttons, one is for normal search when ever some on enter some text in the text box above and clicks on search it will fetch the results.And for the other button, I would like set some default words for search so that when ever some one clicks on
    that.automatically the results will be fetched.

    Any ideas, thanx in advance.

    Regards.

  2. #2
    Join Date
    Jan 2002
    Location
    Charlotte, NC
    Posts
    527
    I'm not understanding why you would want to do that? Instead of using a form for that, why not just use a link?

    -Jason
    http://www.charlottezweb.com
    HOSTING your livelihood

  3. #3
    <FORM METHOD="POST" ACTION="search.php">
    <INPUT TYPE="HIDDEN" NAME="cat" VALUE="DEFAULT SEARCH">
    <INPUT TYPE="SUBMIT" value="Search">
    </FORM>

    In this way you'll always send the same search (your default word).

    For the other button you can leave the form you already have.

  4. #4
    Powi's code will create the form for them to enter search words. I recommend you dont put value="bleh" and just leave that off entirely so its a blank textbox.

    On the search.php (where you will be routed to once they click the Search button) you need something like the following... (I'm assuming you are using PHP and MySQL... if you use another database lemme know or just read up at www.php.net)

    <?php
    if (isset($_POST['cat']))
    {
    $searchForThis = $_POST['cat'];
    $db="databasename";
    $link = mysql_connect('host', 'user', 'password');
    if (!$link)
    die('Could not connect: ' . mysql_error());
    mysql_select_db($db , $link) or die("Couldn't open $db:
    ".mysql_error());

    $result = mysql_query("SELECT * FROM Table WHERE Field LIKE '%$searchForThis%'");
    while ($row = mysql_fetch_array($result))
    {
    echo $row['FieldData'];
    }
    mysql_free_result($result);
    mysql_close($link);
    }
    else
    {
    /*same as above but in the SELECT query you can put whatever you want the default query to be... alternatively you can get rid of the if (isset) syntax above and if they don't provide any search criteria it will return all records since all of them will be LIKE an empty string. */
    }
    ?>

Posting Permissions

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