timmah1 Posted October 29, 2008 Share Posted October 29, 2008 I have a database field named groups. The value for a user is Bowling,Cycling,Tennis,Running Since the values are being inputted like that, numerous values separated by commas, how would I grab that user if someone searches just for Cycling? I was trying to set up a browse feature, but it comes back "No users" Here is my code $groupsql = "SELECT * FROM users WHERE groups = '$id'"; $groupres = mysql_query($groupsql); $numrows = mysql_num_rows($groupres); if($numrows == 0 ) { echo "No users within the $id group"; } $grouprow = mysql_fetch_assoc($groupres); echo $grouprow['first']; Can someone help me out here? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/ Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 try changing: $groupsql = "SELECT * FROM users WHERE groups = '$id'"; with: $groupsql = "SELECT * FROM users WHERE groups LIKE '%".$id."%'"; Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/#findComment-677519 Share on other sites More sharing options...
Maq Posted October 29, 2008 Share Posted October 29, 2008 Not sure I completely understand. So your table could have something like this: user groups ----------------- 1 Bowling,Tennis,Running 2 Bowling,Cycling,Tennis,Running 3 Bowling,Running,Cycling If $id = cycling, you want to grab all of the users with Cycling in their group? So in this case it would be user 1 and 2? Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/#findComment-677523 Share on other sites More sharing options...
timmah1 Posted October 29, 2008 Author Share Posted October 29, 2008 Works perfect now bobbinsbro I tried this earlier $groupsql = "SELECT * FROM users WHERE groups LIKE '%$id%'"; and it didn't work, but it works your way. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/#findComment-677525 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 np please set topic to solved Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/#findComment-677526 Share on other sites More sharing options...
timmah1 Posted October 29, 2008 Author Share Posted October 29, 2008 Exactly Maq. But it would be user 2 and 3 from your example Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/#findComment-677527 Share on other sites More sharing options...
Maq Posted October 29, 2008 Share Posted October 29, 2008 Oh yeah hehe... Quote Link to comment https://forums.phpfreaks.com/topic/130590-solved-selecting-from-mysql/#findComment-677531 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.