Forum Moderators: coopster
If you can help, I'd appreciate it.
I'm trying to do a nested 'do while' but can't seem to get the iteration working right (to be honest I'm not even sure that this is the best solution for what I need to do).
I have two tables with a common field, and (simplified), the code I have is this:
do {
if (condition is met) {
echo $maintopic;
}do {
if (condition is met) {
echo $subtopic;
}} while ($recordset1 = mysql_fetch_assoc($recordset1));
} while ($recordset2 = mysql_fetch_assoc($recordset2));
It runs the outer loop fine, but the inner loop only runs once. Rs1 pulls all the subtopics from one table, and Rs2 pulls all the main topics from another.
The idea is to get something like:
Main Topic 1
Sub topic 1
Sub topic 2
Sub topic 5Main Topic 2
Sub topic 3
Sub topic 4
Sub topic 8
Main Topic 1
Sub topic 1
Sub topic 2
Sub topic 5Main Topic 2
Main Topic 3
Main Topic 4
Thanks,
2odd...
try just building the outside loop, make that work
then I usually insert the query first using the data from the first query, so
while ($result1=mysql_fetch_assoc($query1)) {
print "main title";
$query2="select from..... where section=$result1[section]";
echo '<p>',$query2;
}
this way I can see what's going on and make sure I've properly constructed the queries