Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:41:17+00:00 2026-06-01T05:41:17+00:00

I’m experimenting by making a social network from scratch in PHP/MySQL, but I’m having

  • 0

I’m experimenting by making a social network from scratch in PHP/MySQL, but I’m having trouble thinking of the optimal MySQL structure for it, currently I have:

This is a table which stores all user info:

fname varchar (300),
sname varchar (300),
pass varchar (400),
email varchar (300),
gender varchar (300),
dob varchar (200),
uid varchar (300),
PRIMARY KEY (id)

This is created when a user signs up, their own personal table:

id int(20) NOT NULL auto_increment,
            uid varchar (300),
            photo_url varchar (400),
            pfid varchar (300),
            phototime datetime,
            video_url varchar (400),
            vfid varchar (300),
            videotime datetime,
            status longtext,
            sid varchar (300),
            statustime datetime,
            blog longtext,
            bid varchar (300),
            blogtime datetime,
            about_bio longtext,
            about_current_job longtext,
            about_secondary_school longtext,
            about_primary_school longtext,
            about_college longtext,
            about_university longtext,
            about_workemail longtext,
            about_homeemail longtext,
            about_phonenumber longtext,
            about_relationshipstatus longtext,
            about_relationshipwith longtext,
            PRIMARY KEY (id)
            )";

The sessions table to track whether someone is logged in or not:

id int(20) NOT NULL auto_increment,
sid varchar(300),
uid varchar(300),
PRIMARY KEY (id)

Haven’t gotten onto relationships yet but I was thinking:

id int(20) NOT NULL auto_increment,
requestby varchar(200),
requestto varchar(200),
status varchar(200)

(Before anyone asks, this is purely just for the learning experience, nothing more)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:41:18+00:00Added an answer on June 1, 2026 at 5:41 am

    Well, you definitely shouldn’t have one table per user. I think a database structure more like this would work really well:

    CREATE TABLE users (
        userID INT NOT NULL AUTO_INCREMENT,
        firstName VARCHAR(30),
        lastName VARCHAR(30),
        password CHAR(32), -- should be encrypted, CHAR is better if the field is always the same length
        email VARCHAR(64) NOT NULL, -- not null if this is what you will use as a "username"
        PRIMARY KEY (userID)
    );
    
    CREATE TABLE personalInfo (
        userID INT NOT NULL,
        gender ENUM ('MALE', 'FEMALE'),
        dateOfBirth DATE,
        phoneNumber VARCHAR(15),
        personalEmail VARCHAR(64), -- may or may not be the same as the email field in the "users" table
        workEmail VARCHAR(64),
        bio TEXT,
        FOREIGN KEY (userID) REFERENCES users (userID)
    );
    
    /* this table is not specific to any single user. It is just a list of jobs that have been created */
    CREATE TABLE jobs (
        jobID INT NOT NULL AUTO_INCREMENT,
        company VARCHAR(100),
        title VARCHAR(100),
        description TEXT,
        PRIMARY KEY (jobID)
    );
    
    /* the workInfo table will hold one entry per user per job. So if a user has held five jobs,
       there will be five rows with that userID in this table, each with a different jobID, which
       refers to an entry in the "jobs" table above. */
    CREATE TABLE workInfo (
        userID INT NOT NULL,
        jobID INT NOT NULL,
        startDate DATE,
        endDate DATE, -- can set this to null if it's the user's current job
        FOREIGN KEY (userID) REFERENCES users (userID),
        FOREIGN KEY (jobID) REFERENCES jobs (jobID)
    );
    
    CREATE TABLE schools (
        schoolID INT NOT NULL AUTO_INCREMENT,
        schoolName VARCHAR(100),
        -- any other information you want to provide about the school (city, address, phone, etc)
        PRIMARY KEY (schoolID)
    );
    
    CREATE TABLE schoolPrograms (
        programID INT NOT NULL AUTO_INCREMENT,
        programName VARCHAR(100),
        -- any other information you want to provide about the program (department, teachers, etc)
        PRIMARY KEY (programID)
    );
    
    CREATE TABLE educationInfo (
        userID INT NOT NULL,
        schoolID INT,
        programID INT,
        startDate DATE,
        endDate DATE,
        FOREIGN KEY (userID) REFERENCES users (userID),
        FOREIGN KEY (schoolID) REFERENCES schools (schoolID),
        FOREIGN KEY (programID) REFERENCES schoolPrograms (programID)
    );
    
    CREATE TABLE relationships (
        userID INT NOT NULL,
        userID2 INT, -- allowed to be null if the user is single or does not specify who they are in a relationship with
        status ENUM ('SINGLE', 'IN A RELATIONSHIP', 'MARRIED', 'IT''S COMPLICATED' /* etc */),
        FOREIGN KEY (userID) REFERENCES users (userID)
    );
    
    /* each photo is created here. This way, when a user wants to share a photo,
       we don't have to duplicate each column. We just create another row in
       the "userPhotos" table below that) REFERENCES the same photoID. */
    CREATE TABLE photos (
        photoID INT NOT NULL AUTO_INCREMENT,
        url VARCHAR(200),
        caption VARCHAR(200),
        dateOfUpload TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (photoID)
    );
    
    CREATE TABLE userPhotos (
        userID INT NOT NULL,
        photoID INT NOT NULL,
        FOREIGN KEY (userID) REFERENCES users (userID),
        FOREIGN KEY (photoID) REFERENCES photos (photoID)
    );
    
    /* vidoes, handled exactly the same as photos */
    CREATE TABLE videos (
        videoID INT NOT NULL AUTO_INCREMENT,
        url VARCHAR(200),
        caption VARCHAR(200),
        dateOfUpload TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (videoID)
    );
    
    CREATE TABLE userVideos (
        userID INT NOT NULL,
        videoID INT NOT NULL,
        FOREIGN KEY (userID) REFERENCES users (userID),
        FOREIGN KEY (videoID) REFERENCES videos (videoID)
    );
    
    CREATE TABLE status (
        userID INT NOT NULL,
        status TEXT,
        FOREIGN KEY (userID) REFERENCES users (userID)
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.