Website:
http://www.wcfree.com - This is a Free dating site devoted to people who have came in contact with STD's.

Problem:
I/members want a way to be able to search members based on what they have entered in there "Edit Profile" section. IE: Search for members who are Female, living in Canada and are seeking Friendship.

I have searched through the drupal site and keep seeing "Profileplus". Pretty excited I tried it out. However I is not what I am looking for. This lead me to start developing a different approch.

Goal:
Create a custom search where you can choose which fields you want to show up on the search page. Once you select the options you want. IE: Female, Canada, Friendship. You click submit this takes you to the user listing page. (Trying not to reinvent something that is already working). Now the user listing page will check to see if a search button has been pressed to get you to the page. If it has it will filter the results that meet the options you sent to the page.

Accomplishment So far:
Created a search form: http://www.wcfree.com/profilesearch (The only two fields working are "I am a" and "Country/Area" for testing purposes.) When you click submit your taken to the user listing page and the filters work correctly and display only the users that meet the criteria.

Problems:
1) When displaying the results (say 10 returned) for some reason the user listing page is displaying only a few profiles per page IE: Page 1 = 4, Page 2 = 2, Page 3 = 2. I would like to have all of them on one page unless there is more then 19 then create a new page.
2) In testing I found that searching for umm lets say a Female who is looking for friends and more. There was one person found that matched. However the problem is when displaying Page 1 = Blank, Page 2 = Blank, Page 3 = The lucky member.

I am thinking the listing page does a count and regardless if you pull out profiles on the listing theme it will still return the same number of pages and place the returned members on what ever page it originally set them.

Question:
Has anyone tried this before?
Any suggestion on changing the page count at the theme level?

Code:
[Note: Some people might not agree with the coding style, I will fix it once things are working 100% :D]
profilesearch: This is the code that generates the forms and populates them with the options you provided when creating the profile field.

<?php
// These are the fields we want to show up in the basic search.
$profileFields = "\"profile_imlookingfor\", \"profile_lflivingwith\", \"profile_mwcouple\", \"profile_lfage\", \"profile_lfgender\", \"profile_countryarea\"";

// This is a list of fields that we do not want to show in the search option. 
// IE: Things the members writes about them self.
$profileHideFields = "\"profile_lfaboutmatch\", \"profile_othergreaterthenone\", \"profile_aboutme\"";

$result = db_query(
   'SELECT *
    FROM {profile_fields}
    WHERE name NOT IN (' . $profileHideFields . ')
    AND name IN (' . $profileFields . ') 
    ORDER BY fid'
);

$output .= "\n";
$output='<form action="profile" method="GET">';
$output .= "\n";
$output .= '<table>';
$output .= "\n";

while ($field = db_fetch_object($result)) {
    $output .= '<tr>';
    $output .= "\n";
    $output .= '<td>';
    $output .= "\n";
    $output .=  t($field->title) . ' ' ;
    $output .= '</td>';
    $output .= "\n";
    $output .= '<td>';
    $output .= "\n";

    switch($field->type) {
      case 'selection':
          $output .= "<select name='" . $field->name . "'>";
          $options = $field->required ? array() : array('--');
          $lines = split("[,\n\r]", $field->options);
          foreach ($lines as $line) {
            if ($line = trim($line)) {
              $output .= "\n";
	      $output .= "<option value='" . $line . "'>$line</option>";
             }
          }
          $output .= "\n";
          $output .= '</select>';
          break;
      case 'textfield':
          $output .= "\n";
          $output .= '<input type="textfield" name="$field->name">';
          break;
    }
    $output .= "\n";
    $output .= '</td>';
    $output .= "\n";
    $output .= '</tr>';
}
$output .= '<tr>';
$output .= "\n";
$output .= '<td colspan="2" align="center"><input type="submit" value="Basic Search" name="search"></td>';
$output .= "\n";
$output .= '</tr>';
$output .= '</table>';
$output .= '</form>';
$output .= "\n";
return $output;
?>

profilelisting: Custom theme that displays members

<?php 
// This check makes sure the root user does not show up in the listings page
  if($user->uid != '1') {

     // This checks to see is the Basic Search was used.
     if($_GET['search'] == "Basic Search") {

       // Logic for search terms:
       $profile_mwcouple = $_GET['profile_mwcouple'];
       $profile_countryarea = $_GET['profile_countryarea'];

       // This makes sure to only show profiles that matches what the user is searching for.
       if($profile_mwcouple == $user->profile_mwcouple &&
          $profile_countryarea == $user->profile_countryarea){// &&
         /* $_GET['profile_imlookingfor'] == $user->profile_imlookingfor &&
          $_GET['profile_lfgender'] == $user->profile_lfgender &&
          $_GET['profile_lflivingwith'] == $user->profile_lflivingwith &&
	  $_GET['profile_lfage'] == $user->profile_lfage) {*/
?>

<div id="pro_listing">
   <?php profile_load_profile($user->uid); ?>
  <div class="custom_profiles">
    <TABLE width="98%">
      <TR VALIGN=TOP>
        <TD ROWSPAN=6 WIDTH="120">
          <div class="list_picture" align="center">
            <?php if($user->picture) { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . $user->picture ?>" width="100px" height="100px"></a>
            <?php } elseif($user->profile_mwcouple == "Male") { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . path_to_theme() ?>/images/man.gif" width="100px" height="100px"></a>
            <?php } elseif($user->profile_mwcouple == "Female") { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . path_to_theme() ?>/images/woman.gif" width="100px" height="100px"></a>
            <?php } else { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . path_to_theme() ?>/images/s_default.jpg" width="100px" height="100px"></a>
            <?php } ?>
          </div>			
        </TD>
        <TD>
        </TD>
     </TR>
     <TR class="odd">
       <TD>
         <div class="fields">Name: <a href="user/<?php print $user->uid ?>"><?php print $user->name ?></a></div>
       </TD>
     </TR>
     <TR class="even">
       <TD>
         <div class="fields">City: <?php print $user->profile_mycity ?></div>
       </TD>
     </TR>
     <TR class="odd">
       <TD>
         <div class="fields">Country: <?php print $user->profile_countryarea ?></div>
       </TD>
     </TR>
     <TR class="even">
       <TD>
         <div class="list_headline">
           <?php
             if($user->profile_headline) {
               print $user->profile_headline;
             } else {
               print "This person has not entered there head line yet.";
             }
           ?>
         </div>
      </TD>
    </TR>
    <TR class="odd">
    <TD>
      <div class="list_desc">
        <?php
          if($user->profile_aboutme) {
            print $user->profile_aboutme;
          } else {
            print "This person has not entered there description yet.";
          }
        ?>
     </div>
   </TD>
  </TR>
 </TABLE>
 </div>
</div>
<br />

<?php
       }
  
     } else {
?>
<div id="pro_listing">
   <?php profile_load_profile($user->uid); ?>
  <div class="custom_profiles">
    <TABLE width="98%">
      <TR VALIGN=TOP>
        <TD ROWSPAN=6 WIDTH="120">
          <div class="list_picture" align="center">
            <?php if($user->picture) { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . $user->picture ?>" width="100px" height="100px"></a>
            <?php } elseif($user->profile_mwcouple == "Male") { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . path_to_theme() ?>/images/man.gif" width="100px" height="100px"></a>
            <?php } elseif($user->profile_mwcouple == "Female") { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . path_to_theme() ?>/images/woman.gif" width="100px" height="100px"></a>
            <?php } else { ?>
              <a href="user/<?php print $user->uid ?>"><img src="<?php print base_path() . path_to_theme() ?>/images/s_default.jpg" width="100px" height="100px"></a>
            <?php } ?>
          </div>			
        </TD>
        <TD>
        </TD>
     </TR>
     <TR class="odd">
       <TD>
         <div class="fields">Name: <a href="user/<?php print $user->uid ?>"><?php print $user->name ?></a></div>
       </TD>
     </TR>
     <TR class="even">
       <TD>
         <div class="fields">City: <?php print $user->profile_mycity ?></div>
       </TD>
     </TR>
     <TR class="odd">
       <TD>
         <div class="fields">Country: <?php print $user->profile_countryarea ?></div>
       </TD>
     </TR>
     <TR class="even">
       <TD>
         <div class="list_headline">
           <?php
             if($user->profile_headline) {
               print $user->profile_headline;
             } else {
               print "This person has not entered there head line yet.";
             }
           ?>
         </div>
      </TD>
    </TR>
    <TR class="odd">
    <TD>
      <div class="list_desc">
        <?php
          if($user->profile_aboutme) {
            print $user->profile_aboutme;
          } else {
            print "This person has not entered there description yet.";
          }
        ?>
     </div>
   </TD>
  </TR>
 </TABLE>
 </div>
</div>
<br />

<?php
     }

  }
?>

Comments

jmarkantes’s picture

I haven't looked in full detail at you code, just your description. But it sounds like node profile could help. It took me a little bit to really figure it out and how it helps, but ultimately it allows you to use views more effectively with profiles. Then you could create a view to search certain fields.

Be sure to check out one of the popular nodeprofile tutorials also.

Good luck,
Jason

gurukripa’s picture

i understand ur recco of nodeprofile..i am using the custom core profile module now..and have collected lots of info from many users..

how can this be used with nodeprofile..i dont want to lose all that..

pls suggest.

coommark’s picture

Michelle's tutorial is good. but too complex, will fail any time, uses lots of modules. i think its not very practical, unless, like me, you are british... lol

Dont use it for a hi trafic site. It breaks.

gurukripa’s picture

this seems like good work from your side..though its still not perfect..its headed nicely...and i agree the results are good..

as u said..i think the profile lists are filtered in the same place as is..

could you share information on how you accomplished this ...with details as if you are explaining to a newbie..this will help a lot of people that way...and get your posts into the handbook finally :)

1. How did you make a different looking profile ? Please list the entire process...and instruct on how someone can do this.

2. How did you make the search form ? Where should it be placed etc..

3. How to get the listing as you got it ?

Thanks..hope u will share this info for the benefit of the larger community.....many who see it..may also be able to point out changes to the code...to make it improved.

I assume you are using Drupal 5.1 :)

coommark’s picture

Ya. I think it will greatly help if you let others know a step by step approach to how you achieved this. that will help us test it, and offer better suggestions. cos i wonder.. the theming, were did you place the code? etc, etc, etc.

coommark’s picture

detectedstealth, i believe that your post will give birth to a new revolution in search, especially for dating-style search. God bless you abit.

First let me tell you to avoid the "nodeprofile" thing like plague. It's so shitty how profile searches are achieved through that. I know, cos i have been there! First you need not less that five additional modules to achieve something sexy. And you know for sure, that the less complex, the less the dependancies, the better! So fuck cutting corners. You are on track. Check out www.opentalkng.com and see the sample search i have on the home page. its shitty. it dont work again. and i will take it off altogether and adopt your approach.

Truth is there is no module that will help you seriously - i have searched drupal morethan i search my wife's handbag when she is back from her 'nights out'. so dont look. just stick to your project.

Please keep us updated on progress. to say the truth, i am willing to bear the cost of coding you have done. please keep it up. as a matter of fact, i will implement your code tonight! so help me God and fuck microsoft for Visual Studio, cos i wasted 6 years there!

Forgive me for language, i am French.

gurukripa’s picture

cld u help us understand..step by step..what has to be done to get what you have done..and finally put it up in a small box or something....maybe in a block kind of situation...so people can use it to search for other members....

thanks a lot

detectedstealth’s picture

Wow, I am surprised I had such a response to wards my approach.

I have taken the nodeprofile approach (for now) take a look (http://wcfree.com) just because I wanted to get the site working, because I have members joining every day. [Note: I still like the direction I was heading better I think]

However because of the response I have been getting from this post I will continue working on the direction I was heading.

gurnkripa:
Currently you can copy the code under profile search into a custom block and that would work perfect for you. All that code does is generates the form field and populates them with data that is already in the database. It then sends you to either the user listing page or a custom page you have created with PHP. (That is another approach I was working on.)

coommark:
You have said you would sponsor the coding of this project ;) lol

Seems like there is a big need for this and many people will benefit, I will create a tutorial on my website once I am done I will provide a link.

I will also add a donation section for all of you kind people who wish to support the development. Now that my dating site is working better I will have more time to work on this search feature.

NOTE: The above link (http://www.wcfree.com/profilesearch) is no longer working. I am in moving the example along with a tutorial.
Covering:

  • Profile layout
  • Profile Search: The main project.
  • Gallery support

The site it will be hosted on is: http://drupaldev.wcfree.com

gurukripa’s picture

looking frd to ur tutorial on profile based searching..looked around ur dev side..but cldnt find any tutorial..am i missing something..

stevekerouac’s picture

This is useful stuff. Shame it has not been updated for D6.

detectedstealth’s picture

Hi Steve,

Just wanted to point out, I am working on the new version of my site and will be creating a module for this type of search with D6.

If anyone has any suggestions on how they would like this module to work let me know.