I would like to make a search system like in this site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clintwa
Forum Newbie
Posts: 3
Joined: Sat Dec 21, 2002 2:02 pm

I would like to make a search system like in this site

Post by clintwa »

Hey everyone,

I been hired to create a real estate site and came across this site that has a search system that I would like to incorporate into my site.
http://www.mcgrath.com.au/
I would like to do in php and MySQL. I would like any suggestion or help in making a script like this. I have search most php site for information and unable to get anything that would help me.

Thanks,

Clint
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

What sort of database are you running as a backend in your site?
clintwa
Forum Newbie
Posts: 3
Joined: Sat Dec 21, 2002 2:02 pm

Post by clintwa »

The database will be MySQL.

Any advice would help

Thanks
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

OK whats your time zone?? Where do you live?
clintwa
Forum Newbie
Posts: 3
Joined: Sat Dec 21, 2002 2:02 pm

Post by clintwa »

I live in Charleston, SC - eastern time zone
serambin
Forum Newbie
Posts: 9
Joined: Wed Nov 13, 2002 11:27 pm
Location: Haughton, LA 71037

Search

Post by serambin »

Hi,

Looking at the site you mentioned, a few things may be the case. First, it looks like they are using a field for each major section of town for each listing. The check boxes are pre defined queries yielding all results of each area.

I think I would use the same idea for the --Street or Subdivision -- search as well. That is I woiuld use a 'Keyword' search using 2 fields. One field for the street name and one for the subdivion or area. The database search could look something like this:


Code: Select all

<? $conn = dbconnection();

if ($keyword) &#123;        //Keyword is the input in the text box.

     $k = split(" ", $keyword);
     $num_keywords = count($k);  // For scoring the list of results.
     for ($i=0; $i<$num_keywords; i++) &#123;
          if ($i)
             $k_string .= "or k.keyword = ' ".$k&#1111;$i]. " ' " ;
          else
             $k_string .= "k.keyword = ' ".$k&#1111;$i] . " '  " ;
           &#125;
           $and .= " and ($k_string)  " ;
&#125;

$sql = "select s.id,  // Primary key in database.
                       s.area,          // Area (subdivision) field.
                       10 * sum(k.weight) / $num_keywords as score
             from streets s, keywords k
             where s.id = k.streets
             $and 
             group by s.id, s.area      
             order by score desc, s.id desc";
$result = mysql_query($sql, $conn);

// Now out results

echo "<H2>Here are the results</H2

if (mysql_num_rows($results))  &#123;
  echo "<TABLE>";
  while ($qry = mysql_fetch_array($result))  &#123;
        echo "<TR><TD>";
        echo $qry&#1111;area];
        echo "</TD><TD>;
        echo floor($qry&#1111;score])."%";
        echo "/TD></TR>;
  &#125;
  echo "</TABLE>";
else &#123;
  echo "No match found, try again.";
  &#125;;
?>
Hope this helps,

Stan Rambin
Post Reply