chwebdesigns Posted September 6, 2012 Share Posted September 6, 2012 Hi, I am writing a class application, where students are assigned to a class in a mysql database such as: id student_name class_assignment 001 A Student 1 002 B Student 2 003 C Student 1 004 D Student 1 .... etc. what I want to be able to do is print a table off for each class. I know I could do this individually with an sql such as <?php $sql = "SELECT * from classes where class_assignment='1'"; ?> But what I would like to be able to do is 'report' class 1 register have a page break, then class 2 register etc. in one click - I am unsure at the moment how many classes there are going to be. Is this possible? Hope this makes sense? Many thanks in advance, Cal Quote Link to comment Share on other sites More sharing options...
xyph Posted September 6, 2012 Share Posted September 6, 2012 ORDER BY class_assignment might get you started Quote Link to comment Share on other sites More sharing options...
chwebdesigns Posted September 6, 2012 Author Share Posted September 6, 2012 Thanks for the quick reply I am wanting the output to be in a table for example. So if I order by class_assignment that will list all classes in the one table, where each class needs to be in a separate table on the page, so is there a way of splitting the data up like this? Thanks, Cal Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 6, 2012 Share Posted September 6, 2012 When you're looking at the results, reading down the lines, what tells you that you've come to a new class? If you think about this for a minute, I'm sure you'll see how to solve this in code as well. Quote Link to comment Share on other sites More sharing options...
chwebdesigns Posted September 17, 2012 Author Share Posted September 17, 2012 I have been thinking and thinking about it and still I am not getting anywhere. Obviously what will tell me that I have reached a new class by just looking down the list is when the class_assignment number changes Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 17, 2012 Share Posted September 17, 2012 So, write that in code. Here's the pseudo code. lastID = NULL; while(looping through results){ if(lastID != currentID){ //It's a new class } //All your other code lastID = currentID; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.