Jump to content

select query


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...