Aliasing and Grouping (multiple keyword search)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I followed an online tutorial (url below) to create a simple indexed keyword
search.  The sample as outlined in the tutorial was designed to work with
one keyword only.  I am an experienced PHP programmer with some SQL
experience but only simple queries.  This Aliasing and Grouping is brand new
to me.  What I would like to learn how to do is expand this SQL query to
search for multiple keywords.  The PHP side of things is already taken care
of.  Any help (code, other tutorials, book references, whatever) with the
SQL will be greatly appreciated.

Tutorial at:
http://www.onlamp.com/pub/a/php/2002/10/24/simplesearchengine.html

<?php

## Table structure for table `search_occurrence` ##
/*
CREATE TABLE search_occurrence (
  occurrence_id int(10) unsigned NOT NULL auto_increment,
  word_id int(10) unsigned NOT NULL default '0',
  page_id int(10) unsigned NOT NULL default '0'
  PRIMARY KEY  (occurrence_id)
) TYPE=MyISAM;
*/


## Table structure for table `search_page` ##
/*
CREATE TABLE search_page (
  page_id int(10) unsigned NOT NULL auto_increment,
  page_url varchar(200) NOT NULL default '',
  PRIMARY KEY  (page_id)
) TYPE=MyISAM;
*/


## Table structure for table `search_word` ##
/*
CREATE TABLE search_word (
  word_id int(10) unsigned NOT NULL auto_increment,
  word_word varchar(50) NOT NULL default '',
  PRIMARY KEY  (word_id),
  KEY word_word_ix (word_word)
) TYPE=MyISAM;
*/

include("../includes/db.php"); // opens my database

$query = "
SELECT p.page_url AS url,
COUNT(*) AS occurrences
FROM search_page p, search_word w, search_occurrence o
WHERE p.page_id = o.page_id
AND w.word_id = o.word_id
AND w.word_word = \"$keyword\"
GROUP BY p.page_id
ORDER BY occurrences DESC
LIMIT $start_row, $num_results";

 $result = mysql_query($query, $db);

?>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux