Jump to content

mysql contains string?


Fenhopi

Recommended Posts

I have a system that's supposed to check if your name is in the "likes" column.

	$selectlike2 = "SELECT likes FROM oodles WHERE likes='%$username'";
			$connectselectlike2 = $database->query($selectlike2);
			$selectlikerow2 = mysql_fetch_array($connectselectlike2);
			if($selectlikerow2['likes'] == ""{
				echo "you heaven't liked";
			}
			else{
				echo " you have liked";
			}

 

This doesn't work however. It echos that I haven't liked it (that my username isn't in the likes column) even though it is. Is there a better way of doing this?

 

Link to comment
https://forums.phpfreaks.com/topic/205908-mysql-contains-string/
Share on other sites

You could do.

 

"SELECT likes FROM oodles WHERE likes LIKE '%$username%'";

 

But as has been said, you may want to look at re-designing the base.

And that won't exactly work all the time. Say someone has a Username like David99, that query would also pick up vid99, avid9, etc..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.