Jump to content
Larry Ullman's Book Forums

Recommended Posts



I am some confuse with this matter. I want to print a order list with a title in php. those come from my database. Title is my category name and order list should be my subjects. I used 'institute_category_subject' table and i contain all institutes, categories and their subjects. something like this...



I now need to create my list with these values. It is something like this..


| ics_id | institute_id | category_id | subject_id |
|	  1 |			1 |		   1 |		  2 |
|	  2 |			1 |		   1 |		  4 |
|	  3 |			1 |		   2 |		  2 |
|	  4 |			1 |		   2 |		  3 |
|	  5 |			1 |		   3 |		  1 |
|	  6 |			1 |		   3 |		  4 |



  • sub1
  • sub2
  • sub3


  • sub1
  • sub2
  • sub3 and so on....

My problem is category id with same value going on many rows in the table and when i retrieve that id and when try to print, same category name printing repeatedly. I need to print my category name at only one time as my title and then need to print their subjects as a order list.


any comments are highly appreciated.


thank you..

Link to comment
Share on other sites

If I understand you correctly, what you need is a flag variable. Set this to false initially (outside of the fetching loop). Then, when a new row is fetched, see if the category name is the same as the flag variable. If not, then print the category name and assign its value to the flag variable. This way you'll only print the category name once per category.

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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.


  • Create New...