0

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';

?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by pzuurveen
0

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!

Edited by cereal

0

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

Edited by pzuurveen

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.