Dekieon Posted March 22, 2007 Share Posted March 22, 2007 I am trying to do an include in a while loop and it doesn't work. If have the while loop print out the filename, it loops twice for me, which is how many times it should loop. When I try to include a file it only seems to loop once. $query = "SELECT * FROM `blocklayout` WHERE `column`='right' ORDER BY `weight`"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo " ".$row['filename']; include "./blocks/".$row['filename']; } What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/43852-include-in-a-loop/ Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 $query = "SELECT * FROM `blocklayout` WHERE `column`='right' ORDER BY `weight`"; $result = mysql_query($query) or DIE(mysql_error()); while($row = mysql_fetch_array($result)) { echo " ".$row['filename']; include "./blocks/".$row['filename']; } Try that and see if an error is thrown. Link to comment https://forums.phpfreaks.com/topic/43852-include-in-a-loop/#findComment-213207 Share on other sites More sharing options...
emehrkay Posted March 23, 2007 Share Posted March 23, 2007 frost his query works the problem is in the way you are including your file. I dont see any apparent errors though. try include ('./blocks/'. $row['filename']); Link to comment https://forums.phpfreaks.com/topic/43852-include-in-a-loop/#findComment-213232 Share on other sites More sharing options...
kenrbnsn Posted March 23, 2007 Share Posted March 23, 2007 Do you happen to redefine the variable "$result" in the included file? If you do, you will cause problems with the "while" loop. Can you post the contents of one of the included file? Ken Link to comment https://forums.phpfreaks.com/topic/43852-include-in-a-loop/#findComment-213235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.