Page 1 of 1

Pleasee Help (Query function)

Posted: Thu May 27, 2004 3:33 am
by merican
Hi all,
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>&nbsp;","<b>({page})</b>&nbsp;","<a href="filedb.php?page=1&action=search">« First Page</a>&nbsp;","<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");
		}
	}
}
?>





?>
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




Posted: Thu May 27, 2004 3:47 am
by merican
hi..just want to add something....the department column is a drop down menu....I suspected that this code is wrong:-

Code: Select all

<?php

                        $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");


?>

any comment...please help me

thank you in advance.

Posted: Thu May 27, 2004 3:53 am
by feyd
I don't see department in there, just a comment.. :roll:

Sidenote: There's got to be 30 or so notices that fire off each time the page is accessed.. yikes!

Posted: Thu May 27, 2004 4:04 am
by merican
hi,
that the problem i think. let me tell you a bit about department column. It is a drop down menu indicate by numbers. let say Department A (sub_category_id=1), Department B (sub_category_id=2), Department C (sub_category_id=3) and so on. Admin can add more department is future, thats why is use number to indicate department.
So that why, in below code;

Code: Select all

<?php

                        $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_list']."%'   LIMIT $ffdb->data_bottom,$ffdb->data_top");

?>
department is indicate by sub_category_id.
Thank you..please help

Posted: Thu May 27, 2004 4:23 am
by feyd
I don't think we want to use a wildcard search on the sub_category_id and category_id.. since those have specific relationships

Posted: Thu May 27, 2004 4:37 am
by merican
yeah man...I try to figure out other than that but the problem is, there will be additional department in the future that will be indicate by sub_category_id. I am stuck man.. Can you give any hint to me?

Posted: Thu May 27, 2004 5:02 am
by feyd
since you are using passed data as parameters, you really don't need to worry about future id numbers.. I don't remember how wildcards work on numbers types, but likely.. it'd match 11 and 111 and 121 with passing 1 as the id... you probably don't want that.

so for those, replace the LIKE '%"<whatever>"%' with "= '<whatever>'" (minus the double quotes)

Posted: Thu May 27, 2004 5:06 am
by merican
I really blurr his time...I think i want to made it manual....just put in the department name and not add new department. That will made it better...hahahahahha