using javascript for php search?!?

Javascript coding ..

Moderators: macek, egami, gesf

Post Reply
icu90ucme
New php-forum User
New php-forum User
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Post by icu90ucme » Thu Aug 07, 2003 7:26 pm

this doesn't have any javascript at all but it might help you
this is just a generic search

Code: Select all


// this will be your original search page
  <form action="search_results.php" method="post">
<table width="100%" cellspacing='1'>
  <tr>
   <td>Choose Search Type:<br /></td>
   <td><select name="searchtype" id='dropdown'>
        <option value="option">Option 1</option>
        <option>Option 2</option>
        <option>Option 3</option>
        </select>
  </tr>
  <tr>
   <td>Enter Search Term:<br /></td>
   <td><input name="searchterm" type="text" id='textinput' size="20"></td>
</table>
    <input type="submit" value="Search">
  </form>


and then this is the results page

Code: Select all

  // create short variable names
  $searchtype=$HTTP_POST_VARS['searchtype'];
  $searchterm=$HTTP_POST_VARS['searchterm'];

  // then connect to database and query
  $dbconnect = connection to database
  $query = "select * from table where ".$searchtype." like '%".$searchterm."%'";
  $result = mysql_query($query);

  // see how many hits you got
  $num_results = mysql_num_rows($result);

echo 'Number of entries found: '.$num_results.';

  // show results of search by creating a loop
  for ($i=0; $i <$num_results; $i++)
  {
   $row = mysql_fetch_array($result);

  // put results in a table
  <table width='100%' cellspacing='1'>
  <tr><td>
echo stripslashes($row['entry']);
   </td></tr>
   </table>

 


again this is just generic code but it should be able to get you started in the right direction and throw some ideas in your head

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Post by swirlee » Thu Aug 07, 2003 7:54 pm

The JavaScript you posted doesn't do any actual searching, or much at all, even. There's no decent way to search a site with JavaScript, and MySQL isn't necessarily the way to go. If you're looking for a PHP solution, there are plenty to be Googled. One I just found that looks promising is PHPSiteSearch, which stores the search database in a text file. But I don't know how good it is. There are plenty of PHP search engines to be found at HotScripts, some of which utilize MySQL and some of which do not.

If none of those are what you're looking for, consider using Google's Site Search. The downside is that the search results appear at Google's site, not yours, but the upside is that Google produces damned good search results.

User avatar
ruturajv
php-forum Super User
php-forum Super User
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India
Contact:

MySQL Way

Post by ruturajv » Sun Aug 10, 2003 10:50 pm

An easy way to do it with MySQL is
    [list=]Create a table for search keywords
    [list=]Then populate the table with keywords, and the corresponding hyperlink
on the search page query the keywords and display the corresponding page
[/list]

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: using javascript for php search?!?

Post by swirlee » Mon Aug 11, 2003 6:14 am

ruturajv wrote:An easy way to do it with MySQL is ...


ericehle wrote:... althought I am not able to use mysql on my webserver ...

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests