$abc = '
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
';
//put Search form at the top of the db page.
echo ' Articles DataBase
';
echo $abc.' 
';
if (mb_strlen($path[3]) == 1){ //If db/(.) is a single letter, open links to all pages that start with that letter
$result = mysql_query('select title from db where title REGEXP \'^'.$path[3].'\'');
$c = 0;
echo '';}
echo '| '.$line[0].' | ';
$c++;
if ($c > 2){
echo '';
$c = 0;
}
}
echo '
';
}
elseif (($path[3] == "dbSEARCH") && (isset($_POST['file']))){ //This is the case for the SEARCH being submitted.
$search = $_POST['file'];
if (mb_strlen($search) > 2){
$query = mysql_query('SELECT `title` , `content` FROM `db`
WHERE `'.$_POST['loc'].'` REGEXP \''.$search.'\'');
if (!$query){ echo 'mysql_query error No. 1: '.mysql_error();}
if ($_POST['loc'] == 'title'){
while (($result = mysql_fetch_array($query,MYSQL_NUM)) !== false){
$size[$result[0]] = mb_strlen($result[0]).'}|{'.$result[0];
}
if($size){sort($size,SORT_NUMERIC);}
}
elseif ($_POST['loc'] == 'content'){
while (($result = mysql_fetch_array($query, MYSQL_NUM)) !== false){
preg_match_all("#\b$search\b#Uis",$result[1],$matches);
if (sizeof($matches[0]) == 0){
preg_match_all("#$search#Uis",$result[1],$matches);
$size[$result[0]] = sizeof($matches[0]).'}|{'.$result[0];
}
else $size[$result[0]] = (sizeof($matches[0])+1000).'}|{'.$result[0];
}
if($size){rsort($size,SORT_NUMERIC);}
}
if ($size){
foreach($size as $line){
$result = explode("}|{",$line);
echo ''.$result[1].'
';
}
}
}
else echo ' You cannot search for words less than 3 characters long.
';
}
elseif (mb_strlen($path[3]) > 1){ //case for a specific article.
$path[3] = ereg_replace("_"," ",$path[3]);
$result = mysql_query('select content, title from db where title = \''.$path[3].'\'');
$content = mysql_fetch_array($result,MYSQL_NUM);
echo ''.$content[1].'
'.stripslashes($content[0]).'';
}
elseif (!isset($path[3])){ //case for No article or letter selected.
$id = random_db_id('db');
$result = mysql_query('select content, title from db where id = \''.$id.'\'');
if (!$result){ echo 'query 123a failed: '.mysql_error(); exit;}
$content = mysql_fetch_array($result,MYSQL_NUM);
echo 'Random Article:'.$content[1].'
Surf through the links above to check out some other great articles taken from wikipedia.org!
'.stripslashes($content[0]).'';
}
?>