Jump to content

Search Box Urgent

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
hitman123

hitman123

    Newbie

  • Members
  • PipPip
  • 11 posts
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 */
?>

Edited by Jaan, 16 July 2009 - 04:57 AM.
Please use code tags when you are posting your codes!


#2
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Ahhh like a automatic suggestion for search type thing? Like you might type in g and it will come up with all the results starting with g?

I believe there is something made in PEAR for something like this, Jordan posted it a while ago. Can't remember the name sorry.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#3
hitman123

hitman123

    Newbie

  • Members
  • PipPip
  • 11 posts
Yep. This is what im looking for basically. You type in a search e.g. y and it will display all the results with Y in the search box.

I don't no how this can be done

#4
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
<input type="text" name="query" id="query" size="40" value="<?=$SpecRef?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500" />


#5
hitman123

hitman123

    Newbie

  • Members
  • PipPip
  • 11 posts
Thankyou for your reply, but im still getting the results on a seperate page after inserting that line of coding. see below:

<form action="search.php" method="get">Spec Ref
    <input type="text" name="query" id="query" size="40" value="<?=$SpecRef?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500" />   
<input type="submit" value="Search" />

Edited by Jaan, 16 July 2009 - 05:51 AM.
Please use code tags when you are posting your files!


#6
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Separate page? I dont think you are showing us all of the code.

#7
hitman123

hitman123

    Newbie

  • Members
  • PipPip
  • 11 posts
<form action="search.php" method="get">Spec Ref
    <input type="text" name="query" id="query" size="40" value="<?=$SpecRef?>" action="include/js_suggest/suggest.php" columns="2" autocomplete="off" delay="1500" />   
<input type="submit" value="Search" />

<? 
$myServer = ***;
$myUser = '****;
$myPass = ******;
$myDB = *****;
$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");
  


//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);




//display the results

//textareaContent = "";

while ($row =  mssql_fetch_array($result))
{
$var1=$row["Player"];
$var2=$row["Avg"];
$var3=$row["HR"];
$var4=$row["RBI"];

$textareaContent .= "Name: $var1 Avg: $var2 HR: $var3 RBI $var4 <br/>";
}

if (!isset($var1) || $var1=="") {
  echo $XX;
}

?>
This is the coding

Edited by Jaan, 16 July 2009 - 05:52 AM.
Please use code tags when you are posting your codes!


#8
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Is that search.php?

#9
hitman123

hitman123

    Newbie

  • Members
  • PipPip
  • 11 posts
It is, but i've inserted the form just to shwo you as part of it.

This is search.php:
<? 
$myServer = *****;
$myUser = ***;
$myPass = *****;
$myDB = *****;
$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");
  


//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 . " Record" . ($numRows == 1 ? "" : "s") . " Found </h1>";

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

//textareaContent = "";

//while ($row = @mysql_fetch_array($query))
//{
//$var1=$row["Player"];
//$var2=$row["Avg"];
//$var3=$row["HR"];
//$var4=$row["RBI"];

$textareaContent .= "Spec Ref: $var1 Avg: $var2 HR: $var3 RBI $var4 <br/>";
//}

//if (!isset($var1) || $var1=="") {
  //echo $XX;
//}

?>

Edited by Jaan, 16 July 2009 - 05:53 AM.
Please use code tags when you are posting your codes!


#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Just about anything dynamic like that will require you to learn AJAX techniques.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
As Winged said, AJAX can do this but I believe Jordan mentioned a long time ago there is something made in PEAR for htis?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#12
Ascension

Ascension

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
Yes, You can use PEAR for this, visit the php.net website for more information about it.