am getting an error that "Notice: Undefined variable: new_string in C:\wamp\www\plus256 beta\search.p". someone help me figure out wat's wrong coz am goin nuts.

<?php
        include 'header.php';

        echo '<div align="center">';
        include('class.stemmer.inc');
        include('cleaner.php');
        include('connect.php');



        if(isset($_POST['submit'])){


            $search = $_POST['search'];





                        $stemmer = new Stemmer;
                        $stemmed_string = $stemmer->stem($search);

                        $clean_string = new cleaner();
                        $stemmed_string = $clean_string->parseString($stemmed_string);


                        $split = preg_split("/[ ]/ ",$stemmed_string);
                                  foreach ($split as $array => $value) {
                                  if (strlen($value) > 3) {
                                  continue;
                                  }
                                  $new_string = ''.$value.' ';
                                  }
                        $new_string = substr($new_string,0,(strLen($new_string)-1));


                        $split_stemmed = preg_split("/[ ]/ ",$new_string);




                        $sql = "SELECT DISTINCT COUNT(*) As occurrences, id, title, content, author, reporter, date, comments FROM articles WHERE (";

                        while(list($key,$val)=each($split_stemmed)){
                                  if($val<>" " and strlen($val) > 0){
                                  $sql .= "(title LIKE '%'.$val.'%' OR content LIKE '%'.$val.'%') OR";
                                  }
                        }
                                  $sql=substr($sql,0,(strLen($sql)-3));//this will eat the last OR
                                  $sql .= " GROUP BY id ORDER BY occurrences DESC";





                        $query = mysql_query($sql) or die(mysql_error());
                        $row_sql = mysql_fetch_assoc($query);
                        $total = mysql_num_rows($query);

                        if($total>0) {
                                while ($row_sql = mysql_fetch_assoc($query)) {//echo out the results
                                echo ''.$row_sql['title'].'<br />'.$row_sql['subtitle'].'';
                                }
                        } else
                                {
                                echo "No results to display";
                        }














        }

            echo '</div>';
        include 'footer.php';

?>

It seems your query has an extra opening parenthesis in the WHERE clause:

"SELECT ... FROM articles WHERE (( ... ) OR ( ... ) GROUP BY ..."

So at line 42 remove the first parenthesis. I'm not sure this will fix your problem, if not post the line error, bye!

I think the problem is here
(line 28)

foreach ($split as $array => $value) {
        if (strlen($value) > 3) {
            continue;
            }
        $new_string = ''.$value.' ';
        }

$new_string will only exist if $array contains a value longer than 3 chars

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.