PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
In my system, i want to create a table to display list of students. For each students, i also want to display their marks together. For example, in first row in that table, it will display |John|85|92|... where 85 is his mark for subject A, 92 for subject B and so on. In my opinion, i've to use nested loop like this to do that.
while ($point1 = mysql_fetch_object($result1))
{
...
while ($point2 = mysql_fetch_object($result2))
{
...
}
...
}
First loop is to display list of Students (up-to-down direction) and second loop is to display list of Marks (left-to-right direction). The problem is it doesn't work as i expected. The first loop is ok because it can display all students but second loop got problem because just display marks for the first student only. So anybody got any idea? Feel free to ask me more if my explanation still not enough. Thanx..
Last edited by S_henry on Sun Mar 06, 2005 9:35 pm, edited 1 time in total.
The code here would output the same way I showed the directory listing above... (obviously assuming that the directory structure is strictly as i said and without . and .. )
be careful with performing a query based on another query in a loop.. you can quickly run through available memory for the database. Basically, free the results of the inner query after using it on each iteration of the outer query.
So you run a query on the database right?.... then I'm assuming you're doing what you need to and creating then running the second query from inside the first loop (the query will change for each loop it makes). If you are using a query defined outside the first loop then you'll get whats happening at the moment (since it'll be the same query used over and over).
Correct. I did like d11wtq said. So i'll post my query but on next week because actually right now i'm still on medical leave (at home) and my code is in the office. So keep in touch. Thanx guys..