Jump to content

Recommended Posts

i am trying to do a search function which include stemmer porter algorithm..however..until now it's still error and i have try so hard to find da solution..this is the coding..

 

<?php

include('stemmer.class.inc');

include('cleaner.php');

include('dbconn.php');

     

$stemmer = new Stemmer;

$stemmed_string = $stemmer->stem($string);

 

$clean_string = new cleaner();

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

 

 

$split = 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 = split(" ",$new_string);

           

 

//weighing

 

$sql = "SELECT DISTINCT COUNT(*) As occurrences, title, summary, uploadBy FROM item WHERE (";

           

while(list($key,$val)=each($split_stemmed)){

              if($val<>" " and strlen($val) > 0){

              $sql .= "(title LIKE '%'.$val.'%' OR summary LIKE '%'.$val.'%' OR uploadBy 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['uploadBy'].'';

        }

} else

        {

        echo "No results to display";

}

 

 

?>

 

i use mySQL database version 5..and that error say that..

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') GROUP BY id ORDER BY occurrences DESC' at line 1

 

 

can anybody help me...

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/
Share on other sites

You can only GROUP BY against values that you are actually returning from the query.... in fact you MUST group by all the values you are returning except for those that you are aggregating.

 

And the DISTINCT isn't meaningful here either.

 

 

SELECT COUNT(*) As occurrences, title, summary, uploadBy FROM item 
WHERE ...
GROUP BY title, summary, uploadBy 
ORDER BY occurrences DESC

i've modify the code,but it still has error..i run the code n then the error occur again..it said that:

 

Parse error: syntax error, unexpected T_WHILE in C:\wamp\www\irportal\search.php on line 31

 

the while loop function..how to fix this..is it ok to put loop func in this..

 

$sql = "SELECT COUNT(*) As occurrences, title, summary, uploadBy FROM item WHERE("

           

while(list($key,$val)=each($split_stemmed)){

              if($val<>" " and strlen($val) > 0){

              $sql .= "(title LIKE '%'.$val.'%' OR summary LIKE '%'.$val.'%' OR uploadBy LIKE '%'.$val.'%') OR";

              }

}

              $sql=substr($sql,0,(strLen($sql)-3));//this will eat the last OR

              $sql .= ") GROUP BY title, summary, uploadBy ORDER BY occurrences DESC";

 

thanks a lot for any help.. :)

thanks for ur help king philip..really appreaciate it..

however putting the semicolon at the 1st line is dun bring me the solution..

btw,the while loop func was inside the sql,if i put semicolon...urmm..

the error will occur like this.. :(

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') GROUP BY title, summary, uploadBy ORDER BY occurrences DESC' at line 1

 

i really appreaciate for every help... :)

thanks again king philip..

i've do as ur request..my new code was

 

$sql = "SELECT COUNT(*) As occurrences, title, summary, uploadBy FROM item WHERE(";

//"SELECT DISTINCT COUNT(*) As occurrences, title, summary, uploadBy FROM item WHERE ("

           

while(list($key,$val)=each($split_stemmed)){

              if($val<>" " and strlen($val) > 0){

              $sql .= "(title LIKE '%'.$val.'%' OR summary LIKE '%'.$val.'%' OR uploadBy LIKE '%'.$val.'%') OR";

              }

}

              $sql=substr($sql,0,(strLen($sql)-3));//this will eat the last OR

              $sql .= ") GROUP BY title, summary, uploadBy ORDER BY occurrences DESC";

  echo $sql;

 

and then after running it..this msg occurs..

SELECT COUNT(*) As occurrences, title, summary, uploadBy FROM item WHE) GROUP BY title, summary, uploadBy ORDER BY occurrences DESCYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') GROUP BY title, summary, uploadBy ORDER BY occurrences DESC' at line 1

 

fuhh... :'(

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.