0

I keep getting lost when I look up how to program with MySQL/PHPAdmin in PHP

what I'm trying to make is a contact list that will be stored in MySQL that each user have their own list... I'm new to MySQL what I'm having problems is the structure of how it should be formed in MySQL.. example

user1 ID

user1 bio

user1 email

user1 contacts

user1_contact1 (name, contact bio, contact email)

user1_contact2 (name, contact bio, contact email)

user1_contact3 (name, contact bio, contact email)

user2 ID

user2 bio

user2 email

user2 contacts

user2_contact1 (name, contact bio, contact email)

user2_contact2 (name, contact bio, contact email)

user2_contact3 (name, contact bio, contact email)

so when user1 signs in they see user1 data and user1 contacts and when user2 signs in they see user2 data and user2 contacts

to me it looks like contacts should be a table but what I keep getting confused on is how to make it a user defined table for each user and how the structure should be in PHPMyAdmin

user contacts con be anything like 5 contacts to 5000 contacts.

if there is a better way that I'm missing let me know.

Rob781
  • 3
  • 3
  • 2
    STRONG SUGGESTION: buy a book and/or walk through a few simple PHP/MySQL/HTML tutorials. For example: [PHP MySQL Database](http://www.w3schools.com/php/php_mysql_intro.asp). In your case, it sounds like a) you need a `contacts table`, and b) a `users table`. Each row in your contacts table will have a link to the corresponding "user": it will have a [foreign key](http://www.mysqltutorial.org/mysql-foreign-key/). For example, a "userID" column. Much to learn - but the basics are easy. Honest. – FoggyDay Jan 24 '15 at 20:57
  • Time to think multiple tables with relationship fields like `user_id` – charlietfl Jan 24 '15 at 20:57

1 Answers1

1

Try a user table and a contacts table with the following sql code:

CREATE TABLE MyUsers ( userid BIGINT(20) NOT NULL PRIMARY KEY AUTO_INCREMENT, bio TEXT, email VARCHAR(255) );
CREATE TABLE Contacts ( userid BIGINT(20) NOT NULL FOREIGN KEY, contactid BIGINT(20) NOT NULL);
  • No - "ContactID" is your primary key in the "Contacts" table. "UserId" is the foreign key. And there's really no need for a "BIGINT" - I'd just use "Int". The MySQL examples use "MEDIUMINT". I'd also consider [auto-increment](http://stackoverflow.com/questions/3135804/types-in-mysql-bigint20-vs-int20-etcc_ – FoggyDay Jan 24 '15 at 23:20
  • FoggyDay you are correct, a primary key must be unique, and the userid field in the contacts table will not be unique. – michael kagan Jan 24 '15 at 23:27
  • is this correct 'CREATE TABLE student( user_id int AUTO_INCREMENT, bio varchar(255) NOT NULL, email varchar(255) NOT NULL, PRIMARY KEY(user_id) ); CREATE TABLE contact( contact_no int NOT NULL AUTO_INCREMENT, contact_name varchar(30) NOT NULL, contact_bio varchar(255) NOT NULL, contact_email varchar(255) NOT NULL, PRIMARY KEY(contact_no), FOREIGN KEY(user_id) REFERENCES students(user_id) );' – Rob781 Jan 25 '15 at 01:42
  • also can some one tell me how to type code better on the screen so you call can read it better... everytome it keeps messing up when I type it out??? – Rob781 Jan 25 '15 at 01:48
  • @Michael kagan - please fix your answer. I'd be happy to upvote it afterwards! – FoggyDay Jan 25 '15 at 04:36
  • @Rob781: Just a) edit your text, b) select everything you want to be "code", and then c) Use the "code" symbol ({}) to display it as code. – FoggyDay Jan 25 '15 at 04:40
  • @FoggyDay what Im I doing wrong its not working [code](testings) 'code testing' 'code'(testing) [code](testing) – Rob781 Jan 25 '15 at 14:26