coolguy010 — 2013-06-07T07:07:41-04:00 — #1
im trying to store University Seat number of students in 100+ colleges
- Format of Seat Number - [college code] [batch year] [department] [seat number]
example - if 'ab' is coleg code, '10' batch, 'cs' or computer science dept and seat number is '001'
then Seat Number will be ab10cs001
- Please ignore the seat number '001' and '10' batch as i will not be storing dat ..
- Have 100+ colleges
- Each coleg may have 4 departments , 5 or even 10-12 departments [if ur using array pls use dept, dept... as i will be using this in a for loop..
- There should be a variable [like flag] which will tell if a particular dept exists in the colleg or not ...
pls suggest keepin in mind CPU rsources, memory ...
im just a beginner in PHP ... so any code wil be helpfull..
fretburner — 2013-06-07T07:47:30-04:00 — #2
Could you provide some more details - do you already have the data in a DB and you want a data structure to use for output? Or are you starting from scratch and designing an app? What kind of operations will be done with the data?
coolguy010 — 2013-06-07T08:20:14-04:00 — #3
hii bro.. thanks a lot , really appreciate ur interest in solving my prob..
ill tell you about this part briefly..
and i dont have this in the database, the data is in a file but its not in a proper order.. so have to manually insert the college code and dept in anyway we go..
for every coleg whose coleg code is available i want to generate usn [University Seat Number] for all students of all dept in dat coleg..
this usn will be used in my later code to perform some operations [like one of the operations is to search my db for usn]
Currently im thinking to insert the college code and all the dept of the coleg in database table but getting confused as the no of dept in colleg varies..
fretburner — 2013-06-07T08:33:25-04:00 — #4
Thanks for the extra info.. another question: you said that the data is in a file - do you want to put it into a database, or you'd be just as happy to read the data from the file, process it, and output the results?
coolguy010 — 2013-06-07T08:44:07-04:00 — #5
it will be difficult to read the data from the file as i said its not in a proper order ..
i can manage to write a insertion query to insert that into db, but not able to decide structure of the db table...
if we create PHP class or var, it has to get initialized every time its being executed so i think it wil b good if we insert into db, and then run a select query for all the colleges [one college at a time inside the for loop] .... but even here the select query will b performed multiple times so dnt kno to go with PHP or db way....
fretburner — 2013-06-07T09:36:31-04:00 — #6
OK, so lets think about the db structure to put the data into.. so the seat number and the batch are generated, not stored, right? In which case, I guess all you actually need in your DB table is the college code, and the department code.
Do you have any other data that you'll need to store along with this? If you were going to store additional info about each college, for example, then you'd probably want a separate table for colleges.
coolguy010 — 2013-06-07T09:47:49-04:00 — #7
other info like college name, college location we can add ...
one more thing here is in each coleg , for a particular dept there will b one max no of seats available in dat dept [i.e intake]
example in a college 'XYZ' in 'CS' dept there can be 60 seats available, in 'EC' dept 100 seats available , in another college these numbers may differ...
so to brief up data needed to be stored...
colege code, colleg name, college location, diff depts in dat college, no of seats available in dat dept in that college
fretburner — 2013-06-07T10:06:46-04:00 — #8
So, I think you need two tables.. college and department, which would be something like this:
code <-- as this value is unique to each college, you can use it as the primary key
state <-- add any req fields for the location
id <-- auto-incremented id as the primary key
code <-- department code
college_code <-- foreign key, references the primary key of the college table
That should give you a good structure to build on.. we can easily write a JOIN query to pull out all the data needed to generate the USNs.
coolguy010 — 2013-06-07T10:30:24-04:00 — #9
already trying out with a table structure which i thought...max seats causing lil prob.. if mine doesnt work will try urs..
Thanks a lot bro..
coolguy010 — 2013-06-07T10:37:47-04:00 — #10
and in ur dept table why do we need id ?? we can make a table without that primary key right ? this table is going to become very big so...
fretburner — 2013-06-07T10:45:40-04:00 — #11
The id is there to provide a unique key for each record.. we couldn't any of the other columns as non of them will be unique (there will be multiple records with the same college code, for example).
Edit: Having a primary key speeds up access to the table, too.
coolguy010 — 2013-06-07T10:56:10-04:00 — #12
oh den will add the primary key too... haha.. using ur table structure with an additional table having the names of all the department..