Jump to content


Photo

MYSQL search help


  • Please log in to reply
4 replies to this topic

#1 All4172

All4172
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 05 July 2006 - 08:00 AM

I"m attempting to search MYSQL and if the field keyword has a term that matches the user's keyword, it will display a message saying SORRY KEYWORD ALREADY EXISTS.  So far I'm having no luck.  Here's what I have so far but doesn't work:

$keyword = $_REQUEST['keyword'];
$result = mysql_query("SELECT * FROM joa
WHERE keyword LIKE '%$keyword%''");

if (isset($result)){
echo "Keyword exists";}
else {
echo "Keyword doesn't exist";}


Any advice would be appreciated :)

#2 indalecio

indalecio
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 July 2006 - 08:02 AM

$result = mysql_query("SELECT * FROM joa
WHERE keyword LIKE '%$keyword%' >>'<< ");
The little ' in between then >> << doesn't belong.

#3 All4172

All4172
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 05 July 2006 - 08:10 AM

Good eye ;)

So far though doesn't seem to solve it.  As it is above minus the ', it still returns exists whether the keyword is int he mysql db or not :(

#4 Chips

Chips
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 05 July 2006 - 08:20 AM

I"m attempting to search MYSQL and if the field keyword has a term that matches the user's keyword, it will display a message saying SORRY KEYWORD ALREADY EXISTS.  So far I'm having no luck.  Here's what I have so far but doesn't work:

$keyword = $_REQUEST['keyword'];
$result = mysql_query("SELECT * FROM joa
WHERE keyword LIKE '%$keyword%''");

if (isset($result)){
echo "Keyword exists";}
else {
echo "Keyword doesn't exist";}


Any advice would be appreciated :)

Could try (until someone who's better comes along) this:
if (mysql_num_rows($result) > 0) {
echo "Keyword exists";
} else {
echo "Keyword doesn't exist";
}
and see if that works instead...

#5 All4172

All4172
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 05 July 2006 - 08:24 AM

Could try (until someone who's better comes along) this:

if (mysql_num_rows($result) > 0) {
echo "Keyword exists";
} else {
echo "Keyword doesn't exist";
}
and see if that works instead...


Thanks :)  That works like a charm.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users