Page 1 of 1

need help with mysql match against

Posted: Mon Sep 08, 2008 9:12 pm
by ebonynueve
hi, im new to php mysql. i wanted to try to create a search using match against but i kept getting mysql_num_rows() not a valid mysql. im trying to match the field against the term typed by user. Can anyone help me?


$sql = "SELECT * FROM search_testing WHERE MATCH (first) AGAINST ('$term') ";
$result = mysql_query($sql);

if($term == ""|| $term == null) {
echo 'Enter a search parameter';
exit;
}

if (mysql_num_rows($result)) {
$row = mysql_fetch_assoc($result);
echo $row["first"];
}

Re: need help with mysql match against

Posted: Mon Sep 08, 2008 9:51 pm
by 8ennett
$sql = "SELECT * FROM search_testing WHERE match='userid' (It is best to ensure every query has a unique user id or some kind of unique search query that will pull only ONE result from your DB, otherwise you must implement a query that will only pull ONE result, or enable you to narrow the search down to one at least!)";
$result = mysql_query($sql);

if($term == ""|| $term == null) {
echo 'Enter a search parameter';
exit;
}

OH and also, the incomplete query you left at the bottom of the code:

if (mysql_num_rows($result) < 1) {
echo 'No results matched query!';
}
if (mysql_num_rows($result) > 1) {
echo 'Search paremeters resulted in more than expected!';
}

"There is a lot more expected from this code, I'm just too drunk to notice or care!!!" :D

Re: need help with mysql match against

Posted: Mon Sep 08, 2008 10:06 pm
by ebonynueve
" $sql = "SELECT * FROM search_testing WHERE match='userid' (It is best to ensure every query has a unique user id or some kind of unique search query that will pull only ONE result from your DB, otherwise you must implement a query that will only pull ONE result, or enable you to narrow the search down to one at least!)"; "

when u said unique userid what do you mean? Sorry, i'm just new to this mysql php stuffs. thanx for ur advice tho :D

Re: need help with mysql match against

Posted: Mon Sep 08, 2008 10:40 pm
by 8ennett
ebonynueve wrote:" $sql = "SELECT * FROM search_testing WHERE match='userid' (It is best to ensure every query has a unique user id or some kind of unique search query that will pull only ONE result from your DB, otherwise you must implement a query that will only pull ONE result, or enable you to narrow the search down to one at least!)"; "

when u said unique userid what do you mean? Sorry, i'm just new to this mysql php stuffs. thanx for ur advice tho :D
By a unique userid I mean,

every database entry in to MySQl must either be NULL or NOT NULL right?
If it's NULL then it does not need a default entry, if it is NOT NULL and hasn't received a new entry through a query then MySQL will return an error, UNLESS the figure auto_inrements everytime a new row is added to the table! So in basic terms (and do not accept this as instructions unless you know what you are doing otherwise you could end up in trouble!) everytime you add a new field to the table then the user_id adds +1 to the previous input making a completely new and unique user id number without any help at all from ANYONE!

Auto increment, a valuable necessity in ANY MySQL object orientated website!

Re: need help with mysql match against

Posted: Mon Sep 08, 2008 11:00 pm
by ebonynueve
hmm...i'm not really understanding the bit part about the increment but il try to figure it out. im just testing around actually. Thanx again for teh help :wink: