Search Box urgent

Discussion in 'PHP' started by majidk, Jul 15, 2009.

  1. #1
    I hope you can help, its pretty urgent. I have created a search box which potentially works. But I wish to insert the results in to the text box rather than having them on a new page.

    I have a text box called ref and a search button next to it. so When I put in a search in the ref and click search, the results should appear in the ref text box. I hope you understand what I mean. I know you ahve to define a variable and assign it to the text box, but the question is how> please help.

    Below is the code for the search box:


    <?
    $myServer = 'learoyd-sql';
    $myUser = 'sa';
    $myPass = '25141260';
    $myDB = 'CompanyL';
    $SpecRef = $_GET['query'];
    print ("$SpecRef");



    //connection to the database
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
    or die("Couldn't connect to SQL Server on $myServer");

    <form action="search.php" method="get">
    <input type="text" name="query" id="query" size="40" value="" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500" />
    <input type="submit" value="Search">
    <input type="hidden" name="search" value="1">
    </form>
    <center><a href="search2.php?adv=1">Advanced search</a></center>
    </div>


    //select a database to work with
    $selected = mssql_select_db($myDB, $dbhandle)
    or die("Couldn't open database $myDB");
    //error message (not found message)begins
    $XX = "No Matches Found";
    //query details table begins
    $query = ("SELECT * FROM dbo.DesignControl WHERE Spec_Ref LIKE'$SpecRef%' ");
    // $query = ("SELECT * FROM dbo.DesignProcess");

    print('$query');


    //execute the SQL query and return records
    $result = mssql_query($query);

    $numRows = mssql_num_rows($result);
    echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

    //display the results
    while($row = mssql_fetch_array($result))
    {
    echo "<li>" . $row["Spec_Ref"] . "</li>";
    }
    //close the connection
    mssql_close($dbhandle);

    /*while ($row = @mysql_fetch_array($query))
    {
    $variable1=$row["Player"];
    $variable2=$row["Avg"];
    $variable3=$row["HR"];
    $variable4=$row["RBI"];
    //table layout for results

    print ("<tr>");
    print ("<td>$variable1</td>");
    print ("<td>$variable2</td>");
    print ("<td>$variable3</td>");
    print ("<td>$variable4</td>");
    print ("</tr>");
    }
    //below this is the function for no record!!

    if (!$variable1)
    {
    print ("$XX");
    }
    //end */
    ?>
     
    majidk, Jul 15, 2009 IP
  2. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #2
    You want to display them like a drop down?
     
    jbrooksuk, Jul 15, 2009 IP
  3. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well if you want to do it on the fly without a page reload then your going to need to do it via Ajax or something, if page reload is allowable then just check if the form has been submtited, and if so echo the results inside the text area, else the search hasnt been submitted yet.
     
    wd_2k6, Jul 15, 2009 IP
  4. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #4
    benokshosting.co.uk - search box is in the top right of the menu bar. Type "benoks" in the bar, it drops down with menu items. Do you mean like that?
     
    jbrooksuk, Jul 15, 2009 IP
  5. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Absolutely. i want it in a drop down. how do you do it. This is exactly what im looking for
     
    majidk, Jul 15, 2009 IP
  6. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #6
    Well every result is stored in a table, we use jQuery to pull the data out from the return value.

    You can download the ZIP with everything in, james-brooks.net/downloads/jQuery-Search.zip
     
    jbrooksuk, Jul 15, 2009 IP
  7. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Is it written in java?. what am i modifying? as there is huge amount of information
     
    majidk, Jul 15, 2009 IP
  8. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #8
    I said, jQuery. There isn't anything too confusing.

    Here is the export of some of our MySQL code:
    CREATE TABLE IF NOT EXISTS `search` (
      `id` int(11) NOT NULL auto_increment,
      `url` text NOT NULL,
      `name` text NOT NULL,
      `keywords` text NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
    
    INSERT INTO `search` (`id`, `url`, `name`, `keywords`) VALUES
    (1, 'http://www.benokshosting.co.uk', 'Benoks Hosting', 'Benoks, Hosting, Welcome, Home, Homepage'),
    (2, 'http://www.benokshosting.co.uk/index.php?page=plans', 'Plans', 'plans, packages, copper, bronze, silver, gold, custom'),
    (3, 'http://www.benokshosting.co.uk/index.php?page=support', 'Support', 'support, contact, help, advice, server'),
    (4, 'http://www.benokshosting.co.uk/index.php?page=about', 'About', 'about, company, history, bennett, brooks, benoks'),
    (5, 'http://www.benokshosting.co.uk/index.php?page=contact', 'Contact', 'contact, support, help, information, email'),
    (6, 'http://www.benokshosting.co.uk/forum/index.php', 'Forum', 'forum, community, support, help, online, programming, scripting, server, chat'),
    (7, 'http://www.benokshosting.co.uk/index.php?page=login', 'Client Area', 'client, area, login, register, order, whmcs, packages, plans, hosting, buy now, order'),
    (8, 'http://www.benokshosting.co.uk/services', 'PSD2XHTML', 'PSD, XHTML, HTML, CSS, PSD2XHTML, PSD2HTML');
    
    Code (markup):
    The only file you need to edit is includes/search.php
     
    jbrooksuk, Jul 15, 2009 IP
  9. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Ive just been back on to the site and typed benoks in the search. But i've noticed when you click on the results, it loads onto a new page. I want them results in the text box. Im pretty confused how to do this
     
    majidk, Jul 16, 2009 IP
  10. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    how do i upload the JS query. Ive modified the search.php
     
    majidk, Jul 16, 2009 IP
  11. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #11
    Then it's not what you wanted is it. Do you have an example anywhere?
    Upload files exactly how you download them.
     
    jbrooksuk, Jul 16, 2009 IP
  12. majidk

    majidk Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Please see the following link:

    http://learoyd-sql/test_search.php?query=&search=1

    This is what I have designed. All I want it to do is that the results that are already displayed, I want them removed and want them results in that text box.

    I can post the code if that helps
     
    majidk, Jul 21, 2009 IP
  13. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #13
    The link didn't work, because it's not valid...
     
    jbrooksuk, Jul 21, 2009 IP
  14. Rasputin

    Rasputin Peon

    Messages:
    1,511
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #14
    have you tried what wd_2k6 suggested above?
    that looks like a good answer to me...
     
    Rasputin, Jul 21, 2009 IP
  15. jbrooksuk

    jbrooksuk Active Member

    Messages:
    127
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #15
    The search box I provided uses AJAX to query a PHP page. That right there is AJAX.
     
    jbrooksuk, Jul 21, 2009 IP