tsm1248 Posted November 24, 2010 Share Posted November 24, 2010 Is it possible to have a loop run in a loop ? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 24, 2010 Share Posted November 24, 2010 Yes. Are you having a problem? Quote Link to comment Share on other sites More sharing options...
tsm1248 Posted November 24, 2010 Author Share Posted November 24, 2010 Yes i connect and do the normal routine and i echo out all the rows that have a $row->type==tickets the issue is can i now call from a different table a loop os users into that table? So another question arrises can i loop from another table within a loop Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 24, 2010 Share Posted November 24, 2010 If you're having problems with your code, please post the relevant pieces between tags. Ken Quote Link to comment Share on other sites More sharing options...
tsm1248 Posted November 24, 2010 Author Share Posted November 24, 2010 Scroll all the way to the bottom! <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { can i have another loop here from a different table } ?> Quote Link to comment Share on other sites More sharing options...
tsm1248 Posted November 24, 2010 Author Share Posted November 24, 2010 Sry had to shorten the code..sry it took a little long Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted November 24, 2010 Share Posted November 24, 2010 You can, but ensure you don't use $result as the variable. This should be ok: <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets"; $result = mysql_query($query) or die(mysql_error()); $query = "SELECT * FROM more_tickets"; $result2 = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { while($row = mysql_fetch_array($result2)) { } } ?> Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted November 24, 2010 Share Posted November 24, 2010 Actually, do this also: while($row = mysql_fetch_array($result)) { while($row2 = mysql_fetch_array($result2)) { Quote Link to comment Share on other sites More sharing options...
Jerred121 Posted November 24, 2010 Share Posted November 24, 2010 You can, but ensure you don't use $result as the variable. This should be ok: <?php mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $query = "SELECT * FROM tickets"; $result = mysql_query($query) or die(mysql_error()); $query = "SELECT * FROM more_tickets"; $result2 = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { while($row = mysql_fetch_array($result2)) { } } ?> Unless you want the inner loop to increment the same table as the first loop - i've hade to need to do this a couple of times - it starts getting really confusing when there are about 5-6 embedded loops all incrementing the same thing... Quote Link to comment Share on other sites More sharing options...
tsm1248 Posted November 24, 2010 Author Share Posted November 24, 2010 Thanks guys that worked fantastically can i have a forum within a forum and have the button within the html forum tag send to a different php page <forum> <forum> both forums go to dif pages </forum> </forum> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 24, 2010 Share Posted November 24, 2010 There is no such HTML tag "<forum>". Do mean "<form>"? No, you can not have nested <form> tags. Ken Quote Link to comment Share on other sites More sharing options...
tsm1248 Posted November 24, 2010 Author Share Posted November 24, 2010 Wow just figured it out just placed an if statement on one page for both of them..thanks for all your help guys great community and great people Quote Link to comment Share on other sites More sharing options...
tsm1248 Posted November 24, 2010 Author Share Posted November 24, 2010 OK so the first time loop outputs the first line both loops work then after that only the first loop works? 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.