logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 05-04-2009, 12:46 AM   #1
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default PHP reports

Hello chaps


I am about to undertake some work which involves members taking a test and then recording them into a table. (thats the easy part) i then want to be able to say in 6 weeks be able to download the previous test results by user.

Would it be sensible to just have one table i.e stats_table

And then every time a user enters there results a new data row is added to the table.

Then from there i can then write a variable to look up all user names and pull all the records from a date range??

Also is it possible then to press a button and the a report is created as excel or a csv file?

So many questions i know and i hope this makes sense...
cocoonfx is offline   Reply With Quote
Old 05-04-2009, 08:43 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

what you need is 2 tables

User & Results (1 to many)

You can create these tables and then create a view in MYSQL which joins them virtually. You can query the view as if it were a actual table.

////

With PHP you can write to any file and format.
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 05-04-2009, 09:54 AM   #3
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default

Hello DJ thanks for the quick response.

I never used the VIEW statement before in MySQL

So i imagine when i create the table i would do the following SQL:

Create Table Results Name
`contact_id` int(10) default NULL,
`username` varchar(200) default NULL,
`companyname` varchar(200) default NULL,
VIEW User_Table User_Id
etc etc etc

And then in PHP

Select View User Table From User Id

Etc..
cocoonfx is offline   Reply With Quote
Old 05-04-2009, 10:36 AM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

using EMS MYSQL Manager create a view.

just open a script window...

syntax...

Code:
 
CREATE  VIEW view_name  
AS SELECT * FROM table1 LEFT JOIN TABLE1 ON TABLE1.FIELD1 = TABLE2.FIELD2 etc...
If you called your view 'MYVIEW' and ran the above then a View will be created called MYVIEW. You just reference in your PHP this as if it were a table in its own right.

* Me and Corrosive found an issue with views and its this... Even though we have a different table defined you cannot have fields with the same name in the join!
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 05-04-2009, 11:14 AM   #5
Corrosive
Corrosive's Avatar
 
Join Date: Feb 2008
Location: Bristol, England
Posts: 7,103
Default

Just to add as well...

If you are using PHP myadmin on your server/hosts then you need your primary account details for it to create a view. Don't know why though!
Corrosive is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com