1
Anonymous
How do I make search include modules?
  • 2005/2/16 15:27

  • Anonymous

  • Posts: 0

  • Since:


I have made a module following the instrucions in FAQ with the index.php and xoops_version.php. The page lists data from a table. When I search the site for a word that is in the database table, it doesn't show. When I then try to do an Advanced Search, it offers to search in "News" and "Calendar (piCal)".

How do I make the option to search in all the other modules?

2
Mithrandir
Re: How do I make search include modules?


3
Anonymous
Re: How do I make search include modules?
  • 2005/2/16 15:59

  • Anonymous

  • Posts: 0

  • Since:


Thanks for the quick response!!!!!!!!

I'll give this a look and see what I can do.


Jim

4
Anonymous
Re: How do I make search include modules?
  • 2005/2/16 19:07

  • Anonymous

  • Posts: 0

  • Since:


Ok, I'm having trouble getting this to work. Can you look at my code and let me know what I'm doing wrong? The first list is the table I want to pull from. The second is my search.inc.php file.


The database table:

CREATE TABLE `xoops_rr_rr` (
`id_rr` int(11) NOT NULL auto_increment,
`cuisine_rr` varchar(255) default NULL,
`dress_rr` varchar(255) default NULL,
`name_rr` varchar(255) NOT NULL default '',
`street_address_rr` varchar(255) default '',
`city_rr` varchar(50) default NULL,
`state_rr` varchar(255) NOT NULL default '',
`zipcode_rr` int(10) default '0',
`phone_rr` varchar(15) default NULL,
`email_rr` varchar(255) default '',
`url_rr` varchar(255) default NULL,
`dollar_rr` varchar(255) default NULL,
`food_qa_no_rr` int(3) default '0',
`food_qa_comment_rr` longtext,
`atmosphere__no_rr` int(3) default '0',
`atmosphere__comment_rr` longtext,
`service_no_rr` int(3) default '0',
`service_comment_rr` longtext,
`wine_list_rr` longtext,
`bar_rr` longtext,
`groups` varchar(255) default '',
`children` varchar(255) default '',
`noise_level_rr` varchar(255) default '',
`other_comments_rr` longtext,
`signature_usr_rr` varchar(255) default NULL,
`approved_rr` varchar(4) NOT NULL default 'No',
`date_rr` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id_rr`)
) TYPE=MyISAM AUTO_INCREMENT=21 ;

______________________________________________

Here is my search.inc.php file:


function restaurant_search($queryarray, $andor, $limit, $offset, $userid){
global $xoopsDB;

$sql = "SELECT id_rr,name_rr FROM ".$xoopsDB->prefix("rr_rr")."";

if ( is_array($queryarray) && $count = count($queryarray) ) {
$sql .= " WHERE ((name_rr LIKE '%$queryarray[0]%'";
for($i=1;$i<$count;$i++){
$sql .= " $andor ";
$sql .= "(name_rr LIKE '%$queryarray[$i]%')";
}
$sql .= ") ";
} // end if

$sql .= "ORDER BY id DESC";

$query = $xoopsDB->query("SELECT COUNT(*) FROM ".$xoopsDB->prefix("rr_rr")." WHERE id_rr>0");
list($numrows) = $xoopsDB->fetchrow($query);

$result = $xoopsDB->query($sql,$limit,$offset);
$ret = array();
$i = 0;
while($myrow = $xoopsDB->fetchArray($result)){

$ret[$i]['image'] = "images/url.gif";
$ret[$i]['link'] = "index.php?start=".($numrows-$myrow['id_rr']);
$ret[$i]['name_rr'] = $myrow['name_rr'];
$ret[$i]['uid'] = "";
$i++;
}
return $ret;
}
?>

______________________________________________


I want to be able to search on all the fields.

Any ideas?

5
jensclas
Re: How do I make search include modules?

Bump

6
Anonymous
Re: How do I make search include modules?
  • 2005/2/18 17:11

  • Anonymous

  • Posts: 0

  • Since:


Thanks for the input.

For my information, what id "Bump -

7
rowdie
Re: How do I make search include modules?
  • 2005/2/18 18:42

  • rowdie

  • Just can't stay away

  • Posts: 846

  • Since: 2004/7/21


I see two issues with your sql statements.

1. Look at the ORDER BY line again, it should be a field from your table, and 'id' isn't in your database table. Maybe you intended that to be...

$sql .= "ORDER BY id_rr DESC";


2. This is the part that searches for the word
if ( is_array($queryarray) && $count count($queryarray) ) {
$sql .= " WHERE ((name_rr LIKE '%$queryarray[0]%'";
for(
$i=1;$i<$count;$i++){
$sql .= $andor ";
$sql .= "(name_rr LIKE '%$queryarray[$i]%')";
}
$sql .= ") ";
// end if


Your code only compares the search word with your name_rr field. To compare with other fields you need to add them to this part of the code. For example :
if ( is_array($queryarray) && $count count($queryarray) ) {
$sql .= " WHERE ((name_rr LIKE '%$queryarray[0]%' OR cuisine_rr LIKE '%$queryarray[0]%' OR dress_rr LIKE
                %
$queryarray[0]%')";
  for(
$i=1$i<$count$i++){
  
$sql .= $andor ";
  
$sql .= "(name_rr LIKE '%$queryarray[$i]%' OR cuisine_rr LIKE '%$queryarray[$i]%' OR dress_rr LIKE
                %
$queryarray[$i]%')";
  }
$sql .= ") ";
// end if


I think you had a stray bracket in the sql statement too.

I suggest you start by only adding a few extra fields at a time. I suspect that searching through a large number of fields will slow down your search function if you also have a large amount of data. You'd better test that though, to make sure I'm wrong

Hope that helps,

Rowd

Login

Who's Online

225 user(s) are online (46 user(s) are browsing Support Forums)


Members: 0


Guests: 225


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Sep 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits