Page 1 of 1

whats wrong with this full text search

Posted: Sat Nov 05, 2005 2:39 am
by rami
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


i used this code

Code: Select all

<?php  
   /* call this script "advs.php" */ 
   if(!$c) {  
?> 
<form action="advs.php?c=1" method=POST> 
<b>Find Results with: </b><br> 
Any of these words: <input type="text" length=40 name="any"> <br> 
All of these words: <input type="text" length=40 name="all"> <br> 
None of these words: <input type="text" length=40 name="none"> <br> 
<input type="submit" value="Search"> 
</form> 
<? 
   } else if($c) { 
   MySQL_connect("hostname", "username", "password"); 
       MySQL_select_db("database"); 
   if((!$all) || ($all == "")) { $all = ""; } else { $all = "+(".$all.")"; } 
   if((!$any) || ($any == "")) { $any = ""; }  
   if((!$none) || ($none == "")) { $none = ""; } else { $none = "-(".$none.")"; } 
   $query = " 
       SELECT *, 
          MATCH(title, story) AGAINST ('$all $none $any' IN BOOLEAN MODE) AS score  
          FROM compsite  
       WHERE MATCH(title, story) AGAINST ('$all $none $any' IN BOOLEAN MODE)"; 
      $artm1 = MySQL_query($query); 
      if(!$artm1) {  
         echo MySQL_error()."<br>$query<br>";  
      } 
      echo "<b>Article Matches</b><br>"; 
      if(MySQL_num_rows($artm1) > 0) { 
         echo "<table>"; 
          echo "<tr><td>Score </td><td>Title </td><td>Body</td></tr>"; 
             while($artm2 = MySQL_fetch_array($artm1)) { 
            $val = round($artm2['score'], 3); 
            $val = $val*100; 
            echo "<tr><td>$val</td>"; 
            echo "<td>{$artm2['title']}</td>"; 
            echo "<td>{$artm2['body']}</td></tr>"; 
         } 
      echo "</table>"; 
   } 
   else {  
      echo "No Results were found in this category.<br>";  
   } 
   echo "<br>";  
   }
and gave it a form of page
made all necessary changes

the first error it showed was
undefined variable c in .....

how can it be removed
i named the file
advs.php
but no thing is happening when i click search button....i think the file contains both scripts and code
any changes required
(extracted from zend.com ,tutorials)
thanks
rami


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sat Nov 05, 2005 4:35 am
by timvw
Do you understand what your code does or have you copied it somewhere?
I can only advise you to copy from a different source, because that script seems to rely on register_globals=on in your php configuration, and that has a default value off for years now...

These days we do something like:

Code: Select all

$c = $_POST['somenameofinputbox'];

Posted: Sat Nov 05, 2005 4:53 am
by rami
timvw wrote:Do you understand what your code does or have you copied it somewhere?
I can only advise you to copy from a different source, because that script seems to rely on register_globals=on in your php configuration, and that has a default value off for years now...

These days we do something like:

Code: Select all

$c = $_POST['somenameofinputbox'];
dear sir,
thanks for reply
i dont know how windows was made (codes) but i am still using it...
any way nothing offending

i have already listed that
it is extracted it from http://www.zend.com
its tutorials and there it says nothing
i have understood all in that tutorials...nothing as global or so in that tutorials
any way still it is not running
full tutorials is here
http://www.zend.com/zend/tut/tutorial-ferrara1.php
thanks for reply

Posted: Sat Nov 05, 2005 8:36 am
by timvw
from that article: By Jim Ferrara July 30, 2002

As i said, search for a more recent article, because things have changed since then... The example code is outdated..

At first sight this article might be a good starting point: http://www.phpfreaks.com/pdf/tutorial/1 ... th-PHP.pdf

Posted: Sat Nov 05, 2005 6:16 pm
by rami
timvw wrote:from that article: By Jim Ferrara July 30, 2002

As i said, search for a more recent article, because things have changed since then... The example code is outdated..

At first sight this article might be a good starting point: http://www.phpfreaks.com/pdf/tutorial/1 ... th-PHP.pdf
really thanks
ya i have that article also as i found it through google
as it is some what long i am going though it
hope it works
thanks for all help
really appreciated
rami

Posted: Mon Nov 21, 2005 11:00 am
by rami
ok i have downloaded the file and gone through it i am using as follows

i am using code bb moderator

Code: Select all

<html>
<head><title>Search</title></head>
<body>

<?php
// Full-Text Search Example
// Conect to the database.
require_once ('../mysql_connect1.php');	

// Create the search function:

function searchForm()
{
  // Re-usable form
  
  // variable setup for the form.
  $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : '');
  $normal = (($_GET['mode'] == 'normal') ? ' selected="selected"' : '' );
  $boolean = (($_GET['mode'] == 'boolean') ? ' selected="selected"' : '' );
  
  echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">';
  echo '<input type="hidden" name="cmd" value="search" />';
  echo 'Search for: <input type="text" name="words" value="'.$searchwords.'" />&nbsp;';
  echo 'Mode: ';
  echo '<select name="mode">';
  echo '<option value="normal"'.$normal.'>Normal</option>';
  echo '<option value="boolean"'.$boolean.'>Boolean</option>';
  echo '</select>&nbsp;';
  echo '<input type="submit" value="Search" />';
  echo '</form>';
}


// Create the navigation switch
$cmd = (isset($_GET['cmd']) ? $_GET['cmd'] : '');

switch($cmd)
{
  default:
    echo '<h1>Search Database!</h1>';
    searchForm();
  
  break;
  
  
  case "search":
    searchForm();
    echo '<h3>Search Results:</h3><br />';
    
    $searchstring = mysql_escape_string($_GET['words']);
    switch($_GET['mode'])
    {
      case "normal":
        $sql = "SELECT book_id, bookname,recommend, description, purchaseddate, 
               MATCH(bookname, recommend, description) 
               AGAINST ('$searchstring') AS score FROM books 
               WHERE MATCH(bookname, recommend, description) 
               AGAINST ('$searchstring') ORDER BY score DESC";
      break;
      
      case "boolean":
$sql = "SELECT book_id, bookname,recommend, description, purchaseddate, 
               MATCH(bookname, recommend, description) 
               AGAINST ('$searchstring' IN BOOLEAN MODE) AS score FROM books 
               WHERE MATCH(bookname, recommend, description) 
               AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY score DESC";
      
      break;
    } 
    
    // echo $sql;
    
    $result = mysql_query($sql) or die (mysql_error());
    
    while($row = mysql_fetch_object($result))
    {
      echo '<strong>Title: '.stripslashes(htmlspecialchars($row->bookname)).'</strong><br />';
      echo 'Score:'. number_format($row->score, 1).' Date: '.date('m/d/y', $row->purchaseddate).'<br />';
      echo '<p>'.stripslashes(htmlspecialchars($row->description)).'</p>';
      echo '<hr size="1" />';
    }
  break;
}
?>

</body>
</html>
actually i was not getting diff between code and php bb while posting here s o mr fyed has always some thing to say
i have solve that now :o


it gives the error
Search Database!

Notice: Undefined index: mode in c:program fileseasyphp1-8wwwsearch.php on line 18

Notice: Undefined index: mode in c:program fileseasyphp1-8wwwsearch.php on line 19

Search for: Mode: NormalBoolean

and it shows all record of table
what wrong
do any body has any idea
good tutorial but not working
thanks