Jump to content

Search box


Recommended Posts

Hi

 

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 */

?>

Link to comment
https://forums.phpfreaks.com/topic/166094-search-box/
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.