Jump to content

select query


sugan
 Share

Recommended Posts

Hi,I have 3 tables,1st table list(table name)

lid name1 aaa2 bbb3 ccc
2nd table sub(table name)
id subject1 phy2 che3 bio
3rd table all(table name)
list_lid sub_id date stat1 1 29/1/08 G 2 1 2/2/08 B3 2 25/1/08 G
Now i want as to be listed in the below manner
sub aaa bbb cccphy 29/1/08 2/2/08 -----che ----- ----- 25/1/08bio ----- ----- -----
How to write a query for this...Pls help!
Link to comment
Share on other sites

There's not just one way. I would start by getting the records from the list table, since those values are going across the top of your table. I would save each of those values in an array, so I would get the list of records from the database and loop through them to store each value in an array. Next I would get the list of subjects, since those are the other axis on your output table. I would set up another array and loop through the subject records. For each subject record, I would make a new entry in the array for it. The entry would include the subject name, and then I would loop through the array from the list table and add each of those values as elements in the array entry. I would do another query to look up the values from the all table and store the dates in that array as well. The final result should give an array that looks like this:

Array [  [0] => Array [	"sub" => "phy",	"aaa" => "29/1/08",	"bbb" => "2/2/08",	"ccc" => ""  ],  [1] => Array [	"sub" => "che",	"aaa" => "",	"bbb" => "",	"ccc" => "25/1/08"  ],  [2] => Array [	"sub" => "bio",	"aaa" => "",	"bbb" => "",	"ccc" => ""  ]]

Now you can loop through that array and display each subject on its own line in your output table. It could probably be done a little more efficiently, for example the second query could be a join that gets both the subjects and dates instead of getting the subjects and then getting the dates in a loop.

Link to comment
Share on other sites

Next I would get the list of subjects, since those are the other axis on your output table. I would set up another array and loop through the subject records. For each subject record, I would make a new entry in the array for it. The entry would include the subject name, and then I would loop through the array from the list table and add each of those values as elements in the array entry. I would do another query to look up the values from the all table and store the dates in that array as well. The final result should give an array that looks like this:
I cant make it up correctly, Can u pls tell me the exact code. Pls help!Regards,Suganya
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...