How to store resume details in MySql database - php

I am developing a website (using PHP,MySQL) that deals with resumes of job-seekers. So the database should hold data like education details, projects, skills, etc. I have created different tables for them like shown below.
Basic info table
CREATE TABLE IF NOT EXISTS `candidates` (
`candId` bigint(20) NOT NULL,
`firstName` varchar(255) NOT NULL,
`lastName` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`contact` char(10) NOT NULL,
`address` text NOT NULL,
`gender` char(1) NOT NULL,
)
Experience table
CREATE TABLE IF NOT EXISTS `Experience` (
`candId` bigint(20) NOT NULL,
`companyName` varchar(255) NOT NULL,
`duration` varchar(20) NOT NULL,
`jobRole` varchar(255) NOT NULL,
`workType` varchar(50) NOT NULL
)
Like this,i have created tables for master degree(course,percentage),bachelors degree(course,percentage),skills(name,efficiency),achievements,etc.
In a page,i want to display all the information.For that 10 tables should be accessed in the page.I know that will load the page slowly.Are there any better ways to implement it?

What you need to do is use indexes, foreign keys and MySQL JOIN to achieve the performance.
So Table which have candId should be referenced from main candidates table using foreign keys.
Now when you fetch candidates's all details, use single query using JOIN to get all the candidate's related data. This will help you to improve performance issue.

Related

Foreign key and registration form

I really need help on this and couldn't find any previous questions related to my problem so here I am.
I have a registration form which is split up into 3 stages and therefore 3 tables. Keep in mind I have indexed and created foreign key constraints in phpmyadmin.
First stage is users (table):
CREATE TABLE `dbtest`.`users`(
`user_id` INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`email` VARCHAR(35) NOT NULL,
`password` VARCHAR(50) NOT NULL,
UNIQUE(`email`)
) ENGINE = INNODB;
When a user fills in the first stage and the data is posted into the database and first user_id becomes 1. The user is then redirected onto the next stage (table):
CREATE TABLE `dbtest`.`personal`(
`player_id` INT(5) NOT NULL,
`first` VARCHAR(35) NOT NULL,
`last` VARCHAR(35) NOT NULL,
`mobile` INT(12) NOT NULL,
`parentmobile` INT(12) NOT NULL,
`gender` VARCHAR(6) NOT NULL,
`address` VARCHAR(50) NOT NULL,
`city` VARCHAR(25) NOT NULL,
`postcode` VARCHAR(10) NOT NULL,
`county` VARCHAR(35) NOT NULL,
`country` VARCHAR(35) NOT NULL,
PRIMARY KEY(mobile)
) ENGINE = INNODB;
When he fills in this form all the data gets posted into the database however player_id is 0 not 1. My question is how do I pass the user_id from stage 1 to player_id in stage 2. I have attached pictures my code.
PHP code for Stage 1:
PHP code for Stage 2:
I do not know php, but I have faced similar problems in other languages. What you want, is the id of the last inserted row, right? And then use it to insert the other related parts of the registration.
All you really need to know, is how to find the id:
Object oriented style
mixed $mysqli->insert_id;
Procedural style
mixed mysqli_insert_id ( mysqli $link )
Reference and more info: http://php.net/manual/en/mysqli.insert-id.php

How to write a query that selects / displays form mysql based on users information / input?

I have two tables, users and jobs. I'm trying to write a query that selects and displays a job a user might want based on their input / information. How can I write this query if the data is in two tables?
I'll be displaying the data in a while loop that creates and information card for each match.
any help is much appreciated.
try {
$sql = $dbh->prepare("SELECT * FROM jobs WHERE users");
if($sql->execute()) {
$sql->setFetchMode(PDO::FETCH_ASSOC);
}
}
catch(Exception $error) {
echo '<p>', $error->getMessage(), '</p>';
}
?>
DB structures:
users
user_id` int(5) NOT NULL AUTO_INCREMENT,
`user_name` varchar(25) NOT NULL,
`user_email` varchar(35) NOT NULL,
`user_pass` varchar(255) NOT NULL,
`user_phone` bigint(20) NOT NULL DEFAULT '99',
`user_gender` varchar(20) NOT NULL,
`user_profession` varchar(64) NOT NULL,
`user_min_salary` int(5) NOT NULL,
`user_dob` varchar(10) NOT NULL,
`user_location` varchar(64) NOT NULL,
DB structure jobs:
`vac_id` int(11) NOT NULL AUTO_INCREMENT,
`vac_post_date` varchar(10) NOT NULL,
`vac_deadline` varchar(10) NOT NULL,
`vac_job_title` varchar(64) NOT NULL,
`vac_comp_name` varchar(64) NOT NULL,
`job_description` text NOT NULL,
I think you need to consider and cater for what the link between the job and the users is to be.
Say for example the job_description included mechanic and the user_profession was mechanic then you would have a link between the two tables and you'd then be able to create a query or queries that retrieved the data from the two tables according to that link(match).
To summarise, from what you have shown, you very likely need to think about what will link the two sets of data and then probably amend your tables to cater for the link. Perhaps job_description and user_profession could meet your requirements. However this would likely be very limited.
Kez, regarding your comment, then you'd be looking to JOIN the tables the ON clause perhaps (limitations may restrict this, eg can't do CONTAIN for both) to link the tables. Something along the lines of SELECT * FROM users JOIN jobs ON job_description CONTAINS user_profession;
However, the above would restrict a user to only 1 profession. Note! I haven't checked the SQL so take it more as a pointer.
There are also various flavours of JOIN so perhaps reading up on JOIN could help.

how to maintain records current as well as previous in mysql

Hi any one please help i have a contact table in which i can Insert,Delete,Modify database using PHP web pages....but only current changes will be updated to database. what i want is how i can maintain history of database...
Is there any tutorial for this using (PHP/MYSQL).
I tried creating version of MySQL table for patient... how to proceed further.
CREATE TABLE IF NOT EXISTS `contact` (
`name` varchar(30) NOT NULL,
`phone` varchar(12) NOT NULL,
`mobile` varchar(12) NOT NULL,
`email` varchar(30) NOT NULL,
`address` text NOT NULL,
`conid` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`conid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; # MySQL returned an empty result set (i.e. zero rows).
CREATE TABLE IF NOT EXISTS `contactversion` (
`name` varchar(30) NOT NULL,
`phone` varchar(12) NOT NULL,
`mobile` varchar(12) NOT NULL,
`email` varchar(30) NOT NULL,
`address` text NOT NULL,
`conid` int(11) NOT NULL,
`revision_id` int(11) AUTO_INCREMENT,
type ENUM('INSERT', 'UPDATE', 'DELETE') NOT NULL,
`change_time` DEFAULT current_timestamp,
PRIMARY KEY (`revision_id`)
);
what to do next....
When running the queries to contact, just simply run this right before to take the current contact and copy it in your revision table...
"INSERT INTO
contactversion (name,phone,mobile,email,address,conid,type)
SELECT
name,phone,mobile,email,address,conid,'".$type."' as type
FROM contact
WHERE conid='".$conid."'"
Both tables will require to be identical, with contactversion having type and change_time as additionnal last columns.
It is obvious that this query should be ran before UPDATE and DELETE of the contact table, but after an INSERT. If you are updating multiple contacts with another where clause than the conid, you'll want to consider building the where statement in a variable to use it inside the INSERT's SELECT and the UPDATE/DELETE
While creating contactversions table make sure conid should not be primary key and auto incremented. I hope that is causing the problem.

Jstree table definition

I have integrated Jstree in my application, now i want to understand different column in that table:
CREATE TABLE IF NOT EXISTS `tree` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` bigint(20) unsigned NOT NULL,
`position` bigint(20) unsigned NOT NULL,
`left` bigint(20) unsigned NOT NULL,
`right` bigint(20) unsigned NOT NULL,
`level` bigint(20) unsigned NOT NULL,
`title` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`type` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;
This is the default table provided by the site.
Now if want to add a node, how do i know the value for left, right and level.
This looks like a mix of Adjacency list an nested sets.
Nested sets are a better way of storing trees in a relational database.
It's hard to explain the principle you have to look here and here.
When you use nested sets you don't need parent_id.
I think jstree provided a sample table where you can choose by yourself what technique you use.
Another way of storing trees in a database would be a Closure Table.
It's my personal favourite. It's simple but powerful. But you hardly find anything about it on the net.

Different user roles for logging in with PHP and Mysql

I have a project coming up for doing Admin functions so my question is this. I will try and be clear as possible.
I will have one SUPER-USER who updates all information for other regular-users/people(being our clients).
The clients/regular-users when they log in will only see their info and download files uploaded by SUPER-USER and not see for regular-users.
So if you are Client:#01 you will see the dashboard (welcome page) and your info. Can anyone suggest possible database designs for this.
How to use left/right sql-joins between the user and files table?
UPDATE
I have a users table as well as a company table that the user belongs to. So essentially I want something like this::
$sql = select everything in the users table where the username and pass = to the given form, then left or right join that username to the company that he belong to.
Then they will see their information. if logged in successfully. Because user #01 belongs to company #03 /#01 etc...
USER TABLE looks so
`id` int(11) NOT NULL AUTO_INCREMENT,
`fname` varchar(50) NOT NULL,
'lname` varchar(100) NOT NULL,
`username` varchar(50) ,
`password` varchar(100) ,
`company` varchar(50) // the company name that ther user belongs to
PRIMARY KEY (`id`)
COMPANY table
'id' int(11) not null auto_increment,
'user_id' int(11) //This is to tie the users to this table
'description' varchar(text),
'filename' varchar(25) not null,
'mimetype' varchar (25) not null
PRIMARY KEY ('id')
Well, it depends on how simple or complex you want to go. with something like this I usually will keep it relatively simple and have a main user database (for all users) example:
CREATE TABLE IF NOT EXISTS `user` (
`user_id` int(255) NOT NULL AUTO_INCREMENT,
`user_name` varchar(50) NOT NULL,
`user_pass` varchar(100) NOT NULL,
`user_permissions` tinyint(1) NOT NULL DEFAULT '0',
`active` tinyint(1) NOT NULL DEFAULT '1',
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=MYISAM;
Then I would have possible a second table of permissions depending on how many permissions I was going to have. If all you are going to have is users and super users then you could probably just assign users a value of 0 and then super user a value of 1.
Then in your PHP script it would treat the users different based on their "user_permissions" value.
Now if you are intending to have lots of different levels of permissions then I would definitely create at least one more table to define permissions example:
CREATE TABLE IF NOT EXISTS `permission` (
`permission_id` int(255) NOT NULL AUTO_INCREMENT,
`permission_name` varchar(100) NOT NULL,
`permission_value` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MYISAM;
Then in the permissions table you could assign all sorts of different permissions... read, write, publish, admin, regular user, super user etc.
This is just a very simple starting point. hope that helps.

Categories