-1

I have a php/mysql script which doesn't function! I need to find out how many rows of a string does exist and i have to count from an "boolean full text" function.

this is the code which doesn't function:

$resuslt=mysql_query("SELECT COUNT(homeid) 
                       FROM notes 
                       WHERE MATCH(title, text, tags) AGAINST('+$searchstring*' IN BOOLEAN MODE) AS accurate 
                       FROM notes 
                       WHERE MATCH(title, text, tags) AGAINST ('+$searchstring*' IN BOOLEAN MODE)");

What should i do?

juergen d
  • 201,996
  • 37
  • 293
  • 362
brox
  • 53
  • 7
  • Try to avoid using `mysql_` functions as they are deprecated – bear Jan 23 '15 at 17:25
  • 1
    **Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).** They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). **Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement)** instead, and **use [PDO](http://us1.php.net/pdo).** What do you mean by "doesn't work"? – Jay Blanchard Jan 23 '15 at 17:26
  • 4
    Your query is syntactically incorrect. A single select can only have one `from`. It is also unclear what your intention is. – Gordon Linoff Jan 23 '15 at 17:27
  • 1
    it's not working because you have syntax errors and absolutely NO error handling. at the very bare minimum you should have `$result = mysql_query(...) or die(mysql_error());`. Never assume success. – Marc B Jan 23 '15 at 17:35
  • 1
    What you should do is [check for errors](http://php.net/mysql_error). And stop using deprecated extensions (it could not be more clearly stated in the documentation). – Sverri M. Olsen Jan 23 '15 at 17:36

2 Answers2

0

Does this do what you want?

SELECT COUNT(homeid) 
FROM notes 
WHERE MATCH(title, text, tags) AGAINST('+$searchstring*' IN BOOLEAN MODE) > 0;

If homeid could be repeated, you might really want count(distinct homeid).

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
-1

Is this supposed to be a subselect? if not you have two From's in there:

"SELECT COUNT(homeid) 
                       FROM notes 
                       WHERE MATCH(title, text, tags) AGAINST('+$searchstring*' IN BOOLEAN MODE) AS accurate 
                       FROM notes 
                       WHERE MATCH(title, text, tags) AGAINST ('+$searchstring*' IN BOOLEAN MODE)");

You could try this:

SELECT (SELECT COUNT(homeid) 
                           FROM notes 
                           WHERE MATCH(title, text, tags) AGAINST('+$searchstring*' IN BOOLEAN MODE)) AS accurate
                           FROM notes 
                           WHERE MATCH(title, text, tags) AGAINST ('+$searchstring*' IN BOOLEAN MODE)
picus
  • 1,507
  • 2
  • 13
  • 23