Web Analytics Made Easy -
StatCounter php mysql random selection - CodingForum

Announcement

Collapse
No announcement yet.

php mysql random selection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • php mysql random selection

    Good day, Please Am working on electrical inspection project using php and mysql. I have these table

    Tables: inspection_plan, building, contractor, contractor_tariff, tariff, zone
    inspection_plan
    create table inspection_plan
    (
    inspection_plan_id int not null auto_increment primary key,
    inspection_date date not null,
    inspector_id int not null, //fk
    tariff_id int not null //fk
    building_id int not null //fk
    );

    create table building
    (
    building_id int not null auto_increment primary key,
    building_name varchar(100) not null,
    tariff_id int not null, //fk
    zone_id int not null //fk
    );

    create table contractor
    (
    contractor_id int not null auto_increment primary key,
    contractor_name varchar(100) not null,
    zone_id int not null //fk
    );

    create table tariff
    (
    tariff_id int not null auto_increment primary key,
    tariff_name varchar(100) not null
    );

    create table contractor_tariff
    (
    tariff_id int not null, //fk
    contractor_id int not null //fk
    );

    create table zone
    (
    zone_id int not null auto_increment primary key,
    zone_name varchar(100) not null
    );

    The contractor performs inspection on buildings that are in the same zone with him, and also part of its tariff. Contractor can have several tariff class of building that it can inspect.

    I want to select at random in each year for 3 years 33.3% of buildings from building table and attach a contractor to each building with the same tariff_id and zone_id, and save it in inspection_plan table (automatic select).
    A contractor can inspect more that on building, but a building cannot be inspected by more than one contractor. Also a contractor can have many tariff categories, but a building can only have one tariff category as shown in the tables.

    Please how do I do this.
Working...
X