zssz Posted January 18, 2009 Share Posted January 18, 2009 I am going to start off giving a few example rows to help ask my question (probably not in right "format", but I'm sure you can figure it out): Structure: users, id Data: 132;593;5, 1 500;50, 2 295;95, 3 The data in the `users` table will hold multiple userid's, each separated by a ;. For my site, I need to show data based on the user(s) in the `users` row. So, I want to do something like SELECT * FROM data_table WHERE users='5' . That would show the data in that table (`data_table`) where the user's id was 5, and only 5, otherwise I would use 'like'. Can anyone think of how I would do this in the SELECT query without having to take the data out of the table and seperate it into an array or something? I truly hope that you can understand my question. I tried to explain it the best I could. Thanks! Link to comment https://forums.phpfreaks.com/topic/141306-solved-php-mysql-select-with-varying-data-in-row/ Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 Seems to me that this data would be better of stored within a seperate table with a seperate row for each entry. Have you ever heard of database normalization? Link to comment https://forums.phpfreaks.com/topic/141306-solved-php-mysql-select-with-varying-data-in-row/#findComment-739600 Share on other sites More sharing options...
zssz Posted January 18, 2009 Author Share Posted January 18, 2009 Seems to me that this data would be better of stored within a seperate table with a seperate row for each entry. Have you ever heard of database normalization? A little bit, yes; nothing in depth though. I've never had to do anything like this before, so how would I check that new (separate) table for the userid for the old table's `id`? Only way I could think of is if you name the new row after the userid, but then comes another problem. Think of `id` as a group id. I don't want 50 different tables, 1 per group. But if I named a row after the userid, it would show up for every single group, just null in the groups that the userid doesn't belong to. Link to comment https://forums.phpfreaks.com/topic/141306-solved-php-mysql-select-with-varying-data-in-row/#findComment-739607 Share on other sites More sharing options...
trq Posted January 18, 2009 Share Posted January 18, 2009 This example might help you out. Link to comment https://forums.phpfreaks.com/topic/141306-solved-php-mysql-select-with-varying-data-in-row/#findComment-739610 Share on other sites More sharing options...
zssz Posted January 18, 2009 Author Share Posted January 18, 2009 Ah, alright. I think I get it now. So, to check if a section would be visible to a certain user, I would do SELECT * FROM viewable WHERE users='userid' AND gid='id_of_group' I realize that I could of searched, but I didn't think of it as a "group" until my 2nd post. Thanks for your help, appreciate it. Link to comment https://forums.phpfreaks.com/topic/141306-solved-php-mysql-select-with-varying-data-in-row/#findComment-739618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.