1
bashtler
search.inc.php with more than 1 resultset
  • 2003/12/17 8:28

  • bashtler

  • Just popping in

  • Posts: 12

  • Since: 2003/12/17


Hey

howto create a searchblock for my module with more than one search-resultsets. cuz i have got more than one indipenent table to search and more than one view-php-thing.

so i got no "view all results"-thing in the search result!

greetz

PS: here you got my code. i've copied the file from mydownloads-module and modified it!

//search.inc.php <?php function vertriebspartner_search($queryarray, $andor, $limit, $offset, $userid){ global $xoopsDB; $sql = "SELECT uid, name, uname, email, id_vertriebspartner FROM ".$xoopsDB->prefix("users")." u"; // because count() returns 1 even if a supplied variable // is not an array, we must check if $querryarray is really an array if ( is_array($queryarray) && $count = count($queryarray) ) { $sql .= " WHERE ((u.name LIKE '%$queryarray[0]%' OR u.uname LIKE '%$queryarray[0]%')"; for($i=1;$i<$count;$i++){ $sql .= " $andor "; $sql .= "(u.name LIKE '%$queryarray[$i]%' OR u.uname LIKE '%$queryarray[$i]%')"; } $sql .= ") "; } $sql .= "ORDER BY u.uname DESC"; $result = $xoopsDB->query($sql,$limit,$offset); $ret = array(); $k = 0; while($myrow = $xoopsDB->fetchArray($result)){ $ret[$k]['image'] = "images/head.gif"; $ret[$k]['link'] = "userzuord.php?uid=".$myrow['uid']; $ret[$k]['title'] = $myrow['uname']." (User)"; $k++; } $sql = "SELECT id_vertriebspartner, name FROM ".$xoopsDB->prefix("vertriebspartner")." v"; // because count() returns 1 even if a supplied variable // is not an array, we must check if $querryarray is really an array if ( is_array($queryarray) && $count = count($queryarray) ) { $sql .= " WHERE ((v.name LIKE '%$queryarray[0]%')"; for($i=1;$i<$count;$i++){ $sql .= " $andor "; $sql .= "(v.name LIKE '%$queryarray[$i]%')"; } $sql .= ") "; } $sql .= "ORDER BY v.name DESC"; $result = $xoopsDB->query($sql,$limit,$offset); while($myrow = $xoopsDB->fetchArray($result)){ $ret[$k]['image'] = "images/vp.gif"; $ret[$k]['link'] = "index.php?vid=".$myrow['id_vertriebspartner']; $ret[$k]['title'] = $myrow['name']." (VP)"; $k++; } return $ret; } ?>

2
bashtler
Re: search.inc.php with more than 1 resultset
  • 2003/12/18 12:10

  • bashtler

  • Just popping in

  • Posts: 12

  • Since: 2003/12/17


pace

3
wtravel
Re: search.inc.php with more than 1 resultset

Hi,

Thanks for sharing this code. It will be very usefull for me

regards,

Martijn