syafia Posted March 23, 2009 Share Posted March 23, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/ Share on other sites More sharing options...
Mark Baker Posted March 23, 2009 Share Posted March 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-791574 Share on other sites More sharing options...
syafia Posted March 25, 2009 Author Share Posted March 25, 2009 thank you so much mark barker.. i'll try to change the code.. Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-793267 Share on other sites More sharing options...
syafia Posted March 25, 2009 Author Share Posted March 25, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-793311 Share on other sites More sharing options...
Philip Posted March 25, 2009 Share Posted March 25, 2009 Missing a semicolon on that first line Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-793313 Share on other sites More sharing options...
syafia Posted March 25, 2009 Author Share Posted March 25, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-793325 Share on other sites More sharing options...
Philip Posted March 25, 2009 Share Posted March 25, 2009 Well, it fixed your PHP error - now we have to look at your MySQL error. After this line: $sql .= ") GROUP BY title, summary, uploadBy ORDER BY occurrences DESC"; put: echo $sql; and copy/paste what you see. Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-793326 Share on other sites More sharing options...
syafia Posted March 25, 2009 Author Share Posted March 25, 2009 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... :'( Quote Link to comment https://forums.phpfreaks.com/topic/150677-my-first-search-functionerror/#findComment-793418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.