<?php
// $Id: search.inc.php,v 1.1 2004/07/11 10:28:22 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// License Type   : GPL: See /manual/LICENSES/GPL.txt
// ------------------------------------------------------------------------- //

function mylinks_search($queryarray, $andor, $limit, $offset, $userid) {
global $db;

$sql = "
	SELECT
	lid,
	cid,
	title,
	submitter,
	date,
	LEFT(description, 95) AS content
	FROM ".$db->prefix("mylinks_links")."
	WHERE
	status > 0";

if ( $userid != 0 ) {
	$sql .= " AND submitter=".$userid." ";
}

// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
$count = count($queryarray);
if ( $count > 0 && is_array($queryarray) ) {
	$sql .= " AND ((title LIKE '%$queryarray[0]%' OR description LIKE '%$queryarray[0]%')";
	for ($i=1; $i<$count; $i++) {
		$sql .= " $andor ";
		$sql .= "(title LIKE '%$queryarray[$i]%' OR description LIKE '%$queryarray[$i]%')";
	}
	$sql .= ") ";
}

$sql   .= " ORDER BY date DESC";
$result = $db->query($sql, $limit, $offset);

$i = 0;
if ($result) {
	while ($myrow = $db->fetch_array($result)) {
		$ret[$i]['image']   = "images/home.gif";
		$ret[$i]['link']    = "singlelink.php?lid=".$myrow['lid']."";
		$ret[$i]['title']   = $myrow['title'];
		$ret[$i]['content'] = $myrow['content'];
		$ret[$i]['time']    = $myrow['date'];
		$ret[$i]['uid']     = $myrow['submitter'];
		$i++;
	}
}
return $ret;
}
?>
