Pleasee Help (Query function)
Posted: Thu May 27, 2004 3:33 am
Hi all,
I have a search problem here.Below is my search form template:-
PHP
this is my Class for search:-
ok, here is the problem. As u can see, I have 5 column to search for file.(filename,keyword,author,department and filetype). before this,there is no department column,all work just fine. i just key in some word at one of the column, and the file list will appear.
But now, when i add department column, i only can search file by department. other column is not function. I search for all day and connot find any error.
can somebody please help me to trace the mistake.Thank you in advance.
Regards,
Alfy
I have a search problem here.Below is my search form template:-
PHP
Code: Select all
<form method="POST" action="filedb.php">
<div align="center">
<center>
<div align="center">
<center>
<table border="1" cellpadding="4" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="600" id="AutoNumber3" bgcolor="#009999">
<tr>
<td><b>Search For File</b></td>
</tr>
</table>
</center>
</div>
</center>
</div>
<div align="center">
<center>
<table border="1" cellpadding="4" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="600" id="AutoNumber4" bgcolor="#008080">
<tr>
<td height="19" width="300">Filename:</td>
<td height="19" width="300"><input type="text" name="filename" size="20"></td>
</tr>
<td height="19" width="300">Keyword:</td>
<td height="19" width="300"><input type="text" name="file_description" size="20"></td>
</tr>
<td height="19" width="300">Author:</td>
<td height="19" width="300"><input type="text" name="author" size="20"></td>
</tr>
<td width="100"><font face="Verdana" size="2">Department:</font></td>
<td><select size="1" name="category">{category_list}</select></td>
</tr>
<td height="19" width="300">File Type:</td>
<td height="19" width="300"><input type="text" name="author_site" size="20"></td>
</tr>
</table>
</center>
</div>
<p align="center"><input type="submit" value="Search" name="search"></p>
</form>this is my Class for search:-
Code: Select all
<?php
Class Search {
//*************************************************/
// Just seing what we are doing
//*************************************************/
function Search() {
global $tpl,$mysql,$online,$ffdb;
if ($_REQUEST['action']=="search") {
$this->SearchForm();
}elseif (isset($_REQUEST['search'])) {
$this->SearchResults();
} else {
$ffdb->Error("Well you did something stupid to get this error ");
}
}
//*************************************************/
// Displays our wonderful stats!
//*************************************************/
function SearchForm() {
global $tpl,$mysql,$online,$ffdb,$online,$CONFIG,$admin_skin;
$tpl->LoadTemplate("search_form","templates/$online->skin/search_form.tpl");
//function to call department
$mysql->Query("SELECT ffdb_categorys.*,ffdb_sub_categorys.* FROM ffdb_categorys,ffdb_sub_categorys WHERE ffdb_categorys.category_id=ffdb_sub_categorys.category_id");
while ($show_category=mysql_fetch_array($mysql->result_id)) {
if ($show_category[category_id]==$old_category_id) {
$category_list .="<option value="$show_category[sub_category_id]">-> $show_category[sub_category_name]</option>";
} else {
$category_list .="<option value="none">- - - - $show_category[category_name] - - - -</option><option value="$show_category[sub_category_id]">-> $show_category[sub_category_name]</option>";
}
$old_category_id=$show_category[category_id];
}
$search_form_array = array(
'category_list'=> $category_list,
);
$tpl->ParseTemplate("search_form",$search_form_array,"No");
$tpl->PrintTemplate("search_form");
}
function SearchResults() {
global $tpl,$mysql,$online,$ffdb,$online,$CONFIG;
if (empty($_REQUEST['page']))
{
$page=1;
}
else
{
if (is_numeric($_REQUEST['page']))
{
$page=$_REQUEST['page'];
}
else
{
$ffdb->Error("The page number was not an integer this may be a hacking attempt this has been logged");
}
}
$ffdb->DivideData("SELECT * FROM ffdb_files WHERE file_filename LIKE '%".$_REQUEST['filename']."%'",$page,$CONFIG['files_per_page']);
$ffdb->MakePages("<a href="filedb.php?page={eachpage}&action=search">{eachpage}</a> ","<b>({page})</b> ","<a href="filedb.php?page=1&action=search">« First Page</a> ","<a href="filedb.php?page={eachpage}&action=search">Last Page »</a>",$page,$ffdb->num_pages);
// Loading Our Templates
if ($ffdb->hasdata !="No") {
$tpl->LoadTemplate("file_list","templates/$online->skin/file_list.tpl");
$tpl->LoadTemplate("file_list_top","templates/$online->skin/file_list_top.tpl");
$tpl->LoadTemplate("file_list_bottom","templates/$online->skin/file_list_bottom.tpl");
//$mysql->Query("SELECT * FROM ffdb_files WHERE file_filename LIKE '%".$_REQUEST['filename']."%' LIMIT $ffdb->data_bottom,$ffdb->data_top");
$mysql->Query("SELECT * FROM ffdb_files WHERE file_filename LIKE '%".$_REQUEST['filename']."%' AND author LIKE '%".$_REQUEST['author']."%' AND author_site LIKE '%".$_REQUEST['author_site']."%' AND file_description LIKE '%".$_REQUEST['file_description']."%' AND sub_category_id LIKE '%".$_REQUEST['category']."%' LIMIT $ffdb->data_bottom,$ffdb->data_top");
// Setting up the Sub Category List
while ($show_file=mysql_fetch_array($mysql->result_id)) {
$ffdb->strip_array($show_file);
$date_added=date($CONFIG[date_format],$show_file[date_added]);
if ($show_file[num_ratings]==0) {
$rating=0;
} else {
$rating=round($show_file[total_ratings]/$show_file[num_ratings],2);
}
$file_list_array = array(
'sub_category_id'=>$show_file[sub_category_id],
'file_filename'=> $show_file[file_filename],
'author_site'=> $show_file[author_site],
'date_added'=> $date_added,
'downloads' => $show_file[downloads],
'file_description' => $show_file[file_description],
//'rating' => $rating,
'author'=> $show_file[author],
'file_id' => $show_file[file_id],
);
$tpl->ParseTemplate("file_list",$file_list_array,"Yes");
}
$tpl->ParseTemplate("file_list_top",$file_list_array_top,"Yes");
$file_list_bottom_array = array(
'pages'=> $ffdb->pages
);
$tpl->ParseTemplate("file_list_bottom",$file_list_bottom_array,"Yes");
$tpl->ParseTemplate("file_list_top",$file_list_top_array,"Yes");
$tpl->PrintTemplate("file_list_top");
$tpl->PrintTemplate("file_list");
$tpl->PrintTemplate("file_list_bottom");
} else {
$ffdb->Error("Nothing met your search criteria");
}
}
}
?>
?>But now, when i add department column, i only can search file by department. other column is not function. I search for all day and connot find any error.
can somebody please help me to trace the mistake.Thank you in advance.
Regards,
Alfy