SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use Classes / Structures / Arrays in PHP ? Please Advice

    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[0], dept[1]... 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..

    Thanks

  2. #2
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)
    Hey coolguy,

    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?

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

  4. #4
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)
    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?

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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....

  6. #6
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)
    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.

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)
    So, I think you need two tables.. college and department, which would be something like this:

    college
    code <-- as this value is unique to each college, you can use it as the primary key
    name
    state <-- add any req fields for the location

    department
    id <-- auto-incremented id as the primary key
    code <-- department code
    college_code <-- foreign key, references the primary key of the college table
    max_seats


    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.

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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..

  10. #10
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  11. #11
    SitePoint Mentor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,256
    Mentioned
    32 Post(s)
    Tagged
    5 Thread(s)
    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.

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2013
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh den will add the primary key too... haha.. using ur table structure with an additional table having the names of all the department..

    Thanks


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •