healthserv wrote:
Hi!
I am having a problem searching a fulltext field. I'm setting up a little code library program for a few of us who work together. One field (TEXT) is "keywords" and it is indexed as well as fulltext. I send a simple query via my form to the code below. The connection is successfully made, and I attempt to match my little search (for the word "short") contained in the variable $searchterms. However, I get back the message that $peeky (below) is not a valid MySql resource. Can someone tell me what I am doing wrong? Thanks so much!
Cheers!
-Warren
======= Errant Code follows ===========
$dbh=mysql_connect ("localhost", "something_here", "something_here") or die ('Connection failed because: ' . mysql_error()); mysql_select_db ("thedatabase");
$peeky=MYSQL_QUERY("select MATCH(keywords) AGAINST \"$searchterms\" from CodeLib" ); $peek=mysql_fetch_array($peeky); $howMany=$peek[0];
echo "<br>Howmany=$howMany" ;
=======================================
You checked for errors on mysql_connect, but not for mysql_query. If you had, you would have learned that your query
select MATCH(keywords) AGAINST "$searchterms" from CodeLib
isn't valid SQL. You need to say which columns to select, then say which table, then restrict matches in a WHERE clause. Something like
SELECT id, some_col, some_other_col FROM CodeLib WHERE MATCH(keywords) AGAINST "$searchterms"
See the manual <http://dev.mysql.com/doc/mysql/en/select.html> for details.
Your code would then be something like
$dbh=mysql_connect("localhost", "something_here", "something_here") or die ('Connection failed because: ' . mysql_error()); mysql_select_db("thedatabase", $dbh);
$sql = "SELECT id, some_col, some_other_col FROM CodeLib WHERE MATCH(keywords) AGAINST \"$searchterms\"";
$peeky = mysql_query($sql, $dbh) or die ("Query:<br>\n" . $sql . "<br>\n" . "failed with error:<br>\n" . mysql_error()); $peek = mysql_fetch_array($peeky); $howMany = $peek[0];
echo "<br>Howmany=$howMany" ;
Michael
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]