Code:
getSql.php
/////////////
[CODE]
function get_sql($string){
include("stem.php");
include("cleaner.php");
function get_stemmer($string){
$stemmer = new Stemmer;
$stemmed_string = $stemmer->stem ( $string );
return $stemmed_string;
}
$string=explode(" ",$string);
$size=sizeof($string);
$i=0;
$stemmed_string="";
while($i<$size){
$word=get_stemmer($string[$i]);
$stemmed_string .= " " . $word;
$i++;
}
$clean_string = new jSearchString();
$stemmed_string = $clean_string->parseString ( $stemmed_string );
//echo $stemmed_string . "<br />";
$new_string = ';
foreach ( array_unique ( split ( " ",$stemmed_string ) ) as $array => $value )
{
if(strlen($value) >=2)
{
$new_string .= " " .$value.' ';
}
}
//echo $new_string . "<br />";
$new_string = substr ( $new_string,0, ( strLen ( $new_string ) -1 ) );
//echo $new_string . "<br />";
if ( strlen ( $new_string ) > 3 )
$split_stemmed = split ( " ",$new_string );
$sql = "SELECT DISTINCT COUNT(*) as occurences,id, subject, content FROM pinboard WHERE (";
while ( list ( $key,$val ) = each ( $split_stemmed ) )
{
if( $val!=' && strlen ( $val ) > 0 )
{
$sql .= "((subject LIKE '%".$val."%' OR content LIKE '%".$val."%')) OR";
}
}
$sql=substr ( $sql,0, ( strLen ( $sql )-3 ) );//this will eat the last OR
//$sql .= ") GROUP BY subject ORDER BY occurences DESC LIMIT 10";
$sql .= ") GROUP BY subject ORDER BY occurences DESC ";
return $sql;
}
////////////////////////////////////
index.php
///////////////////////////////////////
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Yourheadstone.com</title>
<style type="text/css">
* {padding:0; margin:0;}
body{
padding:0;
border:0;
background-image:url(../images/bg_images/<?php $num=rand(1,2); $image=$num . ".jpg"; echo $image; ?>);
margin:0;
}
#container {
width:1024px;
height:1005px;
margin:30px auto;
background-image:url(../images/container_images/<?php $num=rand(4,6); $image=$num . ".jpg"; echo $image; ?>);
border-top: 7px solid #80B2E6;
border-right: 5px solid #ADC2DA;
border-bottom: 6px solid #ADC2DA;
border-left: 5px solid #ADC2DA;
}
#headertop{
width:1020px;
height: 90px;
color:#0066CC;
font-size:70px;
padding-left:200px;
float:left;
}
.logo{
margin-left:65px;
margin-top:20px;
font-style:italic;
}
a{
color:#0066CC;
text-decoration: none;
}
#headermiddle{
width:1020px;
height: 45px;
float:left;
}
#headermiddle_left{
width:600px;
height: 45px;
float:left;
}
#headermiddle_right{
width:400px;
height: 45px;
float:left;
}
form{
width: auto;
height: 38px;
text-align:center;
background-color:#000000;
}
input{
line-height: 25px;
font-size: 18px;
height: 30px;
width: 195px;;
}
#headerbottom{
width:1020px;
height: 45px;
background-color:#0AC20A;
float:left;
}
.pagenums{
color:#0C14F7;
}
.page{
color:#0C14F7;
}
.mypage{
background-color:#A7A8B8;
}
img {
border-style:none;
}
#leftcolumn{
width:150px;
height:560px;
float:left;
}
#middlecolumn{
border-top: 7px solid #0A0A0A;
border-right: 5px solid #948F91;
border-bottom: 6px solid #A89D9F;
border-left: 5px solid #8C8587;
padding:10px;
width:720px;
height:560px;
float:left;
background-color:#FFFFFF;
}
.submittime{
color:#00010A;
width:150px;
height:20px;
float:left;
}
#rightcolumn{
width:100px;
height:560px;
float:left;
}
</style>
</head>
<body>
<div id="container">
<div id="headertop"> <a href="index.php"> <span class="logo"> your headstone</span> </a></div>
<div id="headermiddle">
<div id="headermiddle_left">
<a href="index.php"> <img src="../images/flower.gif" alt="image" /></a>
</div>
<div id="headermiddle_right">
<form action="../search_pinboard/search_pinboard_process.php" method="post">
<input type="text" name="search" value="" size="30"/>
<input type="submit" value="search" />
</form>
</div>
</div>
<div id="headerbottom">
<?php
include("getSql.php");
function get_number_of_rows(){
include("../condatabase.php");
mysql_query("SET NAMES 'utf8' COLLATE 'utf8_general_ci'");
$searchStr=$_GET['searchStr'];
$q=get_sql($searchStr);
$result=mysql_query($q,$con)or die(mysql_error());
$rows = mysql_num_rows($result);
return $rows;
}
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($_GET['pagenum'])))
{
$_GET['pagenum'] = 1;
}
$page_rows = 3;
$rows = get_number_of_rows();
if($rows==0){
echo ("<div id=\"no_result\">There are not result.....</div>");
exit;
}
else{
echo ("<div id=\"result\">Total " . $rows . " images." . "<br /></div>");
}
//This tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($_GET['pagenum'] < 1)
{
$_GET['pagenum'] = 1;
}
else if ( $_GET['pagenum'] > $last)
{
$_GET['pagenum'] = $last;
}
function get_max(){
$page_rows = 3;
//This sets the range to display in our query
$max = " limit " .( $_GET['pagenum'] - 1) * $page_rows ."," .$page_rows;
return $max;
}
//echo ("<div class=\"pagenums\">");
// This shows the user what page they are on, and the total number of pages
echo " page " . $_GET['pagenum'] . " of " . $last . "-- ";
// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ( $_GET['pagenum'] == 1)
{
}
else
{
$previous = $_GET['pagenum']-1;
echo " <a class=\"page\" href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> Previous</a> ";
}
$pagenum=$_GET['pagenum'];
$start=1;
$check=$pagenum-3;
if($check<0)
$start=1;
else if($check==0)
$start=1;
else if($check>0)
$start=$pagenum-3;
// echo $start;
$end=$last;
$check=$last-$pagenum;
if($check==0)
$end=$last+1;
else if($check>3)
$end=$pagenum+4;
else if($check<3)
$end=$last+1;
//list all the page number
while($start<$end){
if($pagenum==$start)
echo " <a class=\"mypage\" href='{$_SERVER['PHP_SELF']}?pagenum=$start'> $start </a> ";
else
echo " <a class=\"page\" href='{$_SERVER['PHP_SELF']}?pagenum=$start'> $start </a> ";
$start++;
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ( $_GET['pagenum'] == $last)
{
}
else {
$next = $_GET['pagenum']+1;
echo " <a class=\"page\" href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next page -</a> ";
}
?>
</div>
<div id="leftcolumn"> </div>
<div id="middlecolumn">
<?php
include("../condatabase.php");
//Callback function for preg_replace_callback below
function convert_for_html ($matches) {
$regex[0] = "[";
$regex[1] = "]";
$replace[0] = "[";
$replace[1] = "]";
ksort($regex);
ksort($replace);
$treated = str_replace($regex, $replace, $matches[1]);
$output = '<table class="code"><tr><td>Code:</td></tr><tr><td class="code_box">' . $treated . '</td></tr></table>';
return $output;
}
include("convert_data.php");
global $con;
list_massages();
mysql_close($con);
function list_massages(){
include("../condatabase.php");
$max=get_max();
$searchStr=$_GET['searchStr'];
$q=get_sql($searchStr);
$q=$_SESSION['sql']. $max;
$result=mysql_query($q,$con)or die(mysql_error());
while($row = mysql_fetch_array($result)){
$subject=$row['subject'];
$content=$row['content'];
$id=$row['id'];
$submittime=$row['submittime'];
echo "<a href=\"../pinboard/pinboard_massage.php?id=$id\">";
$subject=output_post($subject);
echo $subject;
echo "</a>";
echo "<br />";
$content=output_post($content);
echo $content;
echo "<br />";
echo "<div class=\"submittime\">";
echo $submittime;
echo "</div>";
echo "<br /><br />";
}
}
function display_username($userid){
include("../condatabase.php");
$q="select * from user where id='$userid'";
$result=mysql_query($q,$con)or die(mysql_error());
while($row = mysql_fetch_array($result)){
$username=$row['username'];
echo $username;
}
}
?>
</div>
<div id="rightcolumn"> </div>
</div>
</body>
</html>
[/CODE]