Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: How can I have two searchform in one?  (Read 524 times)

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
How can I have two searchform in one?
« on: August 04, 2012, 11:47:01 AM »

Hello all, finally I am back after a big adventure.

I make a site with one blog using two snews, structure is
site.com/ snews1
site.com/blog/ snews2

I need to have a searchform  where when someone search in site to display also the results from blog and vice versa.
Or to have some option so user can choose to search from site or blog.

e.g. with drop-down menu, example
Code: [Select]
<div id="search">
<div class="styled-select">
<select name="engines" id="engines" class="select"
<option value="site" selected="selected">Search in site</option>
<option value="blog">Search in blog</option>
</select>
</div>
<?php searchform();?>
</div>

I prefer to make it display the results from both snews but I don't know how to do it!

Any idea how to try to achieve this task.
Logged

Edgardo

  • Newbie
  • *
  • Karma: 1
  • Posts: 22
Re: How can I have two searchform in one?
« Reply #1 on: August 04, 2012, 06:35:40 PM »

Hi, Im very new on this, so Im not give you the details, just an idea as you ask, you should have to make a function thats querrs the db, find the serch function on snews.php copy it on a new file and change a bit the name like if the original is function search you put function search_my or so, there actualy are two search and searchform, copy both and you have to put a name on the file like searches.php or whatever you like then you have to insert a paragraph on your index.php like the one that include your snews.php
 include('snews.php'); include('searches.php'); then you can change them and try, on that way if does not work you just remove the include and not change your snews.php, the other thing is that all the files are in articles, so you shoud make a querry on that table on the db and you could retrive what you need thru sql statments, and coments are in coments table,  so you can maque this on mysqladmin for try your querrys, then insert it inside your function , by the way on aticles table you have some attributes like category position and others but those are the main becouse they reprecent the place where they are in your site, but thats is not clear for me too so i was just to ask that wen i'v  seen your post, hope that can help as an start, others will explane this soon, by the way you have one db? or you have those sites on difrents db, by the way i just inserted some on bold
« Last Edit: August 04, 2012, 07:19:08 PM by Edgardo »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: How can I have two searchform in one?
« Reply #2 on: August 04, 2012, 10:54:37 PM »

I prefer to make it display the results from both snews but I don't know how to do it!
Any idea how to try to achieve this task.

Welcome back Sibas.
I'm not sure how you would go about doing this. Each of your installations is using its own complete file-set, in that it has its own snews.php and index.php file, etc. So, when you are viewing snews1, the search-field will be using the //SEARCH ENGINE function in its snews.php file and it would search the d-base tables snews1 uses. And, when you are viewing snews2 (the blog), the search-field for it uses the //SEARCH ENGINE function in its snews.php file and searches the d-base tables snews2 uses.

If you have the d-base table-sets for both installations in one (the same) database, the names of the tables in one of the table-sets would be prefixed with its own identifier. For example, the d-base tables for snews1 would be using their default table names (articles, categories, etc.) and the d-base tables for snews2 (blog) could be prefixed with blog_ to make them unique to the snews2 installation.

In order to have the //SEARCH ENGINE function search the table-sets for both installations, and be able to do it from both sites, we would need to modify the //SEARCH ENGINE function in both snews.php files so that it queries both sets of tables in the database simultaneously. Right now (by default) it queries the articles and categories tables. So we would need to figure out how to make it query the articles and categories tables and the the blog_articles and blog_categories tables.

I am not sure how to do that though... perhaps someone else does?  ???
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: How can I have two searchform in one?
« Reply #3 on: August 05, 2012, 01:58:59 PM »

Thanks Edgardo and Keyrocks!
I think I have make one to work, although is kind odd!! [Need lot of testing]

First of all I use [WIP] Ajax Search, so if you try mine odd version need to installed first
http://snewscms.com/forum/index.php?topic=8824.0
the reason I use it is I don't like to redirect every time when someone make a search to search result page.

So let's start! The structure as I said is

site.com (one file snews with his one db)
site.com/blog (another file snews with his one db)

I start making two php files

1) config.php for snews site, copy and comment out function db($variable) put it in file,
include this file in snews include('searchEngines.php'); YES IT'S CORRECT ADDED LIKE THIS

2) config-blog.php for snews blog, do the same and put it in config-blog.php
include the file in snews  include('../searchEngines.php'); YES IT'S CORRECT ADDED LIKE THIS

3) In config-blog.php change the $db to $db2 like this
Code: [Select]
<?php
// CONFIGURE DATABASE VARIABLES
function db2($variable) {
   
$db2 = array(
      
'dbhost' => 'localhost',
      
'dbname' => 'blog',
      
'dbuname' => 'name',
      
'dbpass' => 'pass',
      
'prefix' => ''
   
);
return 
$db2[$variable];
}
?>


In blog snews do the same, in function connect_to_db() AND function show_status()
Code: [Select]
function connect_to_db() {
   $db2 = mysql_connect(db2('dbhost'), db2('dbuname'), db2('dbpass'));
   mysql_query("SET NAMES 'utf8'");
   mysql_select_db(db2('dbname')) or die(l('dberror'));
   if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '"._PRE.'articles'."'")) != 1) {
         die(l('db_tables_error'));
   }
}

4) Make one file in root searchEngines.php [Please change both actions to your site]
Code: [Select]
<?php
include('config.php');
include(
'config-articles.php');
function 
searchform() { ?>

   <form id="search_engine" method="post" action="http://127.0.0.1/site/" accept-charset="UTF-8">
      <p><input class="searchfield" name="search_query" type="text" id="keywords" size="45" value="Search Keywords" onfocus="document.forms['search_engine'].keywords.value='';" onblur="if (document.forms['search_engine'].keywords.value == '') document.forms['search_engine'].keywords.value='Search Keywords';" />
      <input class="searchbutton" name="submit" type="submit" value="GO" /></p>
   </form>
<?php }

function 
searchform_blog() { ?>

   <form id="search_engine_blog" method="post" action="http://127.0.0.1/site/blog/" accept-charset="UTF-8" style="display:none">
      <p><input class="searchfield" name="search_query" type="text" id="keywords" size="45" value="Search Keywords in blog" onfocus="document.forms['search_engine_blog'].keywords.value='';" onblur="if (document.forms['search_engine_blog'].keywords.value == '') document.forms['search_engine_blog'].keywords.value='Search Keywords in blog';" />
      <input class="searchbutton" name="submit" type="submit" value="GO" /></p>
   </form>
<?php }
?>


5) In both index.php (site and blog) change the searchform() to
Code: [Select]
<div id="search">
<div class="styled-select">
<select id="chooseform" class="select">
    <option value="site" selected="selected">Search in Site</option>
    <option value="Blog">Search in Blog</option>
</select>
</div>
<?php searchform();?>
<?php searchform_blog();?>
</div>

6) Add the following js [change if need both URL $.post]
Code: [Select]
  $('#search_engine').submit(function(){
      var arg = $('#search_engine').serialize();
      $.post(
         'http://127.0.0.1/site/',
         arg + '&ajaxSearch=yes',
         function( data ) {
         $('.results') .html(data);
         }
      );
      return false;
   });
   
   $('#search_engine_blog').submit(function(){
      var arg = $('#search_engine_blog').serialize();
      $.post(
         'http://127.0.0.1/site/blog/',
         arg + '&ajaxSearch=yes',
         function( data ) {
         $('.results') .html(data);
         }
      );
      return false;
   });

           $('#search_engine').show();
            $('#search_engine_blog').hide();
    $('#chooseform').change(function() {
        var choice = $(this).val();
        if (choice == "Blog")
        {
            $('#search_engine_blog').show();
            $('#search_engine').hide();
        }
        else if (choice == "site")
        {
            $('#search_engine_blog').hide();
            $('#search_engine').show();
        }
    });


And that's it!
So far all test I have make Is working, I can choose to search in blog or site and have the proper results ;D

I need one help for styling I try to do it like gmail in search, if someone knows any tutorial for this kind of style please added.
« Last Edit: August 05, 2012, 02:02:21 PM by sibas »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: How can I have two searchform in one?
« Reply #4 on: August 05, 2012, 07:46:55 PM »

Quote from: sibas
I need one help for styling I try to do it like gmail in search

You mean something like this? http://ball-ball.net/beta/search.php :P
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: How can I have two searchform in one?
« Reply #5 on: August 05, 2012, 07:54:31 PM »

Fred K thanks! Yes something like this I looking
I try to find how to make it work with select and option
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: How can I have two searchform in one?
« Reply #6 on: August 10, 2012, 05:02:46 PM »

Hm, combining a <select> thing with thesearch field sounds like an adventure, to say the least ;)
Meanwhile, I've taken my beta design and made a fuller website theme out of it. More info here: http://snewscms.com/forum/index.php/topic,10490.msg69360.html#new
Or here: http://frdk.com/
If you're interested. ;)
Logged