Jump to content

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..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.