Jump to content

[SOLVED] PHP, MySQL Select with varying data in row


zssz

Recommended Posts

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!

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.

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.

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.