0; ?>
Results for "” . $_GET[‘q’] . “"
“;
$start = 0;
$limit = 10;
if(array_key_exists(‘pg’,$_GET) and $_GET[‘pg’]>1)
{
$start+=($_GET[‘pg’]-1)*$limit;
}
$db = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME,$db);
$sql=”(SELECT post_title SourceName, guid SourceURL, quotes.meta_value Quote, authors.meta_value Author
FROM `wp_posts`
JOIN wp_postmeta quotes ON quotes.`post_id`=wp_posts.ID AND quotes.meta_key=’Quote’
LEFT JOIN wp_postmeta authors ON authors.`post_id`=wp_posts.ID AND authors.meta_key=’QuoteAuthor’
WHERE wp_posts.post_status=’publish’”;
$sqlCount=”(SELECT count(*) Count
FROM `wp_posts`
JOIN wp_postmeta quotes ON quotes.`post_id`=wp_posts.ID AND quotes.meta_key=’Quote’
LEFT JOIN wp_postmeta authors ON authors.`post_id`=wp_posts.ID AND authors.meta_key=’QuoteAuthor’
WHERE wp_posts.post_status=’publish’”;
foreach(split(” “,$_GET[‘q’]) as $qWord)
{
$sql.=” AND (quotes.meta_value LIKE ‘%$qWord%’ OR authors.meta_value LIKE ‘%$qWord%’)”;
$sqlCount.=” AND (quotes.meta_value LIKE ‘%$qWord%’ OR authors.meta_value LIKE ‘%$qWord%’)”;
}
$sql.=”) UNION (SELECT SourceName, QuoteURL, Quote, QuoteAuthor Author
FROM external_quotes WHERE 1=1 “;
$sqlCount.=”) UNION (SELECT count(*) Count
FROM external_quotes WHERE 1=1 “;
foreach(split(” “,$_GET[‘q’]) as $qWord)
{
$sql.=”AND (Quote LIKE ‘%$qWord%’ OR QuoteAuthor LIKE ‘%$qWord%’)”;
$sqlCount.=”AND (Quote LIKE ‘%$qWord%’ OR QuoteAuthor LIKE ‘%$qWord%’)”;
}
$sql.=”) LIMIT $start,$limit”;
$sqlCount.=”)”;
//echo $sql;
$result = mysql_query($sql,$db);
$resultCount = mysql_query($sqlCount,$db);
//echo mysql_error();
if(mysql_num_rows($result)>0)
{
while($row = mysql_fetch_array($result))
{
echo “
“
” . $row[‘Author’] . “
” .
“
” . $row[‘Quote’] . “
“;
if($row[‘SourceName’])
echo “
Found in ” . $row[‘SourceName’] . “
“;
echo “
“;
}
$count=0;
while($row = mysql_fetch_array($resultCount))
{
$count+=$row[‘Count’];
}
$prevpg = $_GET[‘pg’]-1;
$nextpg = ($_GET[‘pg’])?$_GET[‘pg’]+1:2;
echo “
if($prevpg>0)
{
echo “<<Previous results – “;
}
if($count>$start+$limit)
{
echo “See more results for "” . $_GET[‘q’] . “">>“;
}
echo “
“;
}
else
{
echo”
“;
}
}
?>