It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Profiles

Moderator: Malcolm

Profiles

Postby Johnathan on Sat Sep 20, 2008 9:06 pm

Ok, I want to make something where each user has their own profile. What way should I set up the database? Just have the table with all users? Or have a table per user so they can add more fields? Or would I be able to have in the table something like extra1, extra2 etc then let them name and fill out the field?

Also I would like to have a search bar that searched the profiles, the forum and other stuff on the site, everything will be in a database so would I just make it search in there? And could I exclude certain fields like password and things like that?
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby flabbyrabbit on Sat Sep 20, 2008 10:13 pm

If you want each user to be able to create their own sections then it makes it more complicated than a straight forward members profile. The way you would have to do it is to have two separate tables linked by a primary key (e.g. user_id). So the first table would contain the users information. The second table would have something like user_id, name, body. So when the user adds a new section their user_id goes in the user_id field and the name and body of what they want to add goes in the other fields. Then on the users profile page it will have to get information from both tables, and get all the records from the second table with the same user_id.

For the search you could create a mysql query using the LIKE clause, therefore you would be able to choose which fields it will search.

Hope that helps, wasn't explained very well =[
Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby Johnathan on Sat Sep 20, 2008 10:28 pm

I got lost at complicated :roll: lol j/k But why would it need the two tables? Could I not have one long table like user_id, name, password, email, biography, website etc So have everything that's needed in there? just don't see the need for both the tables.
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby flabbyrabbit on Sat Sep 20, 2008 10:46 pm

I thought you said you wanted the user to be able to add extra items/fields. If not then you can do it with one table.

Flabby Rabbit
Image
User avatar
flabbyrabbit
500+ Club
 
Posts: 706
Joined: Thu Jan 25, 2007 1:10 pm
Location: Midlands, England

Postby Johnathan on Sun Sep 21, 2008 9:43 am

It would be good for them to add extra fields, but I don't want them being unlimited. i was thinking of having something like extra12, extra2 so they choose what they want in there. You know what I mean?
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby nighthawk on Sun Sep 21, 2008 7:52 pm

You could put all that in one big table, but it is better to use two, or even more. You should use one table for basic data like user_id (unique number that is assigned automatically when user registers, set that field to auto_increment), username, password, email, and other table(s) for extra data. Reason for having two or more tables is that you won't have to waste space on empty fields when a user doesn't supply all the data. Depending on the size to what your website will grow this could have significant impact on performance.

Using a table per user is pointless.

If you already have a forum use it's search.

If you are making your own search it is easy to choose what to search for, search only works on table fields that you select, you have to write a query, something like

SELECT username,email FROM basic_user_data WHERE username='$username'...

So if you don't write a query to read password they will be excluded. Also remember to always hash your passwords.
The Zeitgeist Movement
User avatar
nighthawk
250+ Club
 
Posts: 420
Joined: Sun Jun 11, 2006 1:53 pm
Location: SFRJ

Postby Johnathan on Sun Sep 21, 2008 7:55 pm

Ok, thanks for that, and how do I hash my passwords?
Johnathan
1000+ Club
 
Posts: 1207
Joined: Thu May 31, 2007 3:28 pm
Location: Belfast, Northen Ireland

Postby nighthawk on Sun Sep 21, 2008 8:36 pm

Use something like
[php]$password=sha1($password);[/php]

or look at my topic.
I think that hashing is safer when you make function like this. After all security (logon process) is something that doesn't really have to run fast, no one will notice half a second lag (rough estimate), but they will notice if their password gets cracked.
The Zeitgeist Movement
User avatar
nighthawk
250+ Club
 
Posts: 420
Joined: Sun Jun 11, 2006 1:53 pm
Location: SFRJ


Who is online

Users browsing this forum: No registered users and 0 guests