I have the following code, and database. My intent is the end user can select the colums from a database (by ‘ajax’ing option/selects direct from mysql) and run a report on them. I can predetermine the tables they use, they pick the columns.
my biggest problem is the BEST way to perform a ‘schedule’ query.
To run a schedule i need the Details from ‘Customer’ and ‘Delivery’ – (customer info and delivery address) and i use the ‘custnum’ from all tables, plus the year, to choose which yearly schedule to run – ie custnum bar12345 – yearly schedule table is bar123452012
there could be 2 products per ‘custnum’ pulled from the bar123452012 table.
this table is just a single row per product, but 367 columns, 1- prodid, and 366 titled with the
yday
integer. php works out if it needs to use 365 or 366 in that year in a different function.
What would you suggest? A php loop to pull all customers one by one and format in a table, or is there an SQL query that will Left Join a different table to each row based on the tindex . 2012id?!
need speed and efficiency as we are talking at least 200 customer tables, maybe up to 1000.
Thanks to Dwurf for a reality check. Reorganised database to have one schedule table, and work from that.
Thanks Dwurf. New design being worked on all afternoon… Database
Table structure for table customer
custnum varchar(255) No
surname varchar(50) No
name varchar(50) No
phone1 varchar(50) No
phone2 varchar(50) No
email varchar(50) No
add1 varchar(50) No
add2 varchar(50) No
city varchar(50) No
postcode varchar(10) No
Table structure for table deliverydetails
special varchar(50) No
add1 varchar(50) No
add2 varchar(50) No
city varchar(50) No
postcode varchar(10) No
custnum varchar(100) No
Table structure for table notes
custnum varchar(50) No
notes varchar(50) No
time timestamp No CURRENT_TIMESTAMP
Table structure for table prodgroups
pgroup varchar(20) No
name varchar(50) No
description varchar(50) No
Table structure for table products
name varchar(50) No
quantity varchar(50) No
description varchar(50) No
pgroup varchar(50) No
price varchar(50) No
picture varchar(100) No
productid varchar(10) No
suppid varchar(50) No
vat tinyint(1) No
Table structure for table schedule
productid varchar(15) No
d0 varchar(100) No
d1 varchar(100) Yes NULL
d2 varchar(100) Yes NULL
…….
d362 varchar(100) Yes NULL
d363 varchar(100) Yes NULL
d364 varchar(100) Yes NULL
d365 varchar(100) Yes NULL
custnum varchar(50) No
id int(50) No
Table structure for table suppliers
suppid varchar(50) No
name varchar(50) No
phone1 int(100) No
phone2 int(100) No
email varchar(100) No
add1 varchar(50) No
add2 varchar(50) No
city varchar(50) No
postcode varchar(10) No
description varchar(100) No
Table structure for table vatgroups
vat int(20) No
amount decimal(20,0) No
description varchar(20) No
This approach is suicidal for performance
This isn’t really possible with the design you outline in your question. A design change might help though: if you have a single table for all of your reports and you add a column for the report name you will be a bit closer. Consider something like:
Now you can construct a query to grab all rows for a particular customer
Use PHP (or whatever you’re using) to generate the table from these results.
I know this strategy breaks your ‘direct table access from UI’ model, but I’m afraid that model simply doesn’t work very well. Change your design to work with the tools you have instead of trying to force the tools to conform to your design.