Fenhopi Posted June 26, 2010 Share Posted June 26, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205908-mysql-contains-string/ Share on other sites More sharing options...
Pikachu2000 Posted June 26, 2010 Share Posted June 26, 2010 Echo your query string and look at the value the username must be identical to in order to return a result. Quote Link to comment https://forums.phpfreaks.com/topic/205908-mysql-contains-string/#findComment-1077493 Share on other sites More sharing options...
Alex Posted June 26, 2010 Share Posted June 26, 2010 First you should start off my fixing your database design. Storing multiple items in a single column usually connotes bad database design. Quote Link to comment https://forums.phpfreaks.com/topic/205908-mysql-contains-string/#findComment-1077527 Share on other sites More sharing options...
jcbones Posted June 26, 2010 Share Posted June 26, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205908-mysql-contains-string/#findComment-1077623 Share on other sites More sharing options...
Alex Posted June 26, 2010 Share Posted June 26, 2010 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.. Quote Link to comment https://forums.phpfreaks.com/topic/205908-mysql-contains-string/#findComment-1077665 Share on other sites More sharing options...
jcbones Posted June 26, 2010 Share Posted June 26, 2010 True, that is why the last line is in there. Quote Link to comment https://forums.phpfreaks.com/topic/205908-mysql-contains-string/#findComment-1077722 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.