allin44 Posted July 22, 2009 Share Posted July 22, 2009 I know this is probably VERY sloppy code, but here is my issue. I am trying to build something similar to the "blocks" you get in most prebuilt PHP CMS. So I have developed a table in my database that lists what blocks are to go on what side of what page etc. Use PHP to bring them out, and an include to include that blocks info in the container.. Issue: I have two blocks that should go on the "left" side. One is a USER CP and one is a news feed. Using the code I will post below, the first box comes out just dandy, no issues at all, displays properly etc. The 2nd one however, WILL NOT display at all, and I dont mean just the content, I mean the second container won't show at all. It's not generating any error codes, I have no overlapping vars in any of the files that are being included, and if I just strip the include out and do an echo $fileloc or whicever I have named the variable, the 2nd container comes out just fine, so I cannot for the life of me figure out why it won't display properly.. HELP! <table class="left_nav" cellspacing="0px" cellpadding="0"> <? include("../private/functions/db_info.php"); $con = mysql_connect($server,$db,$pw); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $result = mysql_query("SELECT * FROM blocks where page = '$page'"); while($row = mysql_fetch_array($result)) { echo "<tr><td class='left_nav_header'>".$row['desc']."</td></tr>"; //header echo "<tr class='left_nav_content_row'><td class='left_nav_content'>"; $x = $row['location']; // gets block page location $incfile = "../Blocks/$x"; // declares it as Blocks/location/file.php"; require($incfile); echo "</td></tr><tr><td class='left_nav_footer'></td></tr>"; //footer echo "<tr class= 'spacer'><td> </td></tr>"; } ?> </table> Link to comment https://forums.phpfreaks.com/topic/166900-solved-php-include-in-loop-pulling-file-location-from-a-db/ Share on other sites More sharing options...
xtopolis Posted July 22, 2009 Share Posted July 22, 2009 Well, does the mysql query return more than 1 row? Link to comment https://forums.phpfreaks.com/topic/166900-solved-php-include-in-loop-pulling-file-location-from-a-db/#findComment-879992 Share on other sites More sharing options...
allin44 Posted July 22, 2009 Author Share Posted July 22, 2009 Well, does the mysql query return more than 1 row? As I mentioned in the text, if I take out the include and just use echo $fileinc; both show up properly and it displays the correct file locations.. First attachment is what displays if I use the include Second is what displays if I just print the var $incfile [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/166900-solved-php-include-in-loop-pulling-file-location-from-a-db/#findComment-879994 Share on other sites More sharing options...
xtopolis Posted July 22, 2009 Share Posted July 22, 2009 Ok, didn't see that part, sorry. What is the content for the first file being required? There is probably something there holding up the script... I made myself a basic example with: r1.php <?php echo 'hi1'; ?> r2.php <?php echo 'hi2'; ?> example.php <?php $ar = array( array("desc"=>'desc1', "location"=>'r1'), array("desc"=>'desc2', "location"=>'r2'), ); ?> <table class="left_nav" cellspacing="0px" cellpadding="0"> <?php foreach($ar as $row) { echo "<tr>\n\t<td class='left_nav_header'>".$row['desc']."</td>\n</tr>\n"; //header echo "<tr class='left_nav_content_row'>\n\t<td class='left_nav_content'>"; $x = $row['location']; // gets block page location $incfile = $x . '.php'; // declares it as Blocks/location/file.php"; require($incfile); echo "</td>\n</tr>\n<tr>\n\t<td class='left_nav_footer'></td>\n</tr>\n"; //footer echo "<tr class= 'spacer'>\n\t<td> </td>\n</tr>"; echo "\n\n"; } ?> </table> And it seemed to come out ok. So, let us see the content of the first (and maybe second) file being required.. Link to comment https://forums.phpfreaks.com/topic/166900-solved-php-include-in-loop-pulling-file-location-from-a-db/#findComment-880014 Share on other sites More sharing options...
allin44 Posted July 22, 2009 Author Share Posted July 22, 2009 File One $con = mysql_connect($server,$db,$pw); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $result = mysql_query("SELECT * FROM user_cp_links"); while($row1 = mysql_fetch_array($result)) { echo "<a href='".$row1['link']."'>".$row1['description']."</a><br>"; } This displays just fine File Two $con = mysql_connect($server,$db,$pw); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db", $con); $result = mysql_query("SELECT * FROM news"); while($row = mysql_fetch_array($result)) { echo $row['news']; } I realize both files are pretty bare right now, but I just want to get it working before I start doing all the customizing Link to comment https://forums.phpfreaks.com/topic/166900-solved-php-include-in-loop-pulling-file-location-from-a-db/#findComment-880503 Share on other sites More sharing options...
allin44 Posted July 22, 2009 Author Share Posted July 22, 2009 doh.. I fixed it.. I changed result to result1 in the first file and its all good now.. woops Link to comment https://forums.phpfreaks.com/topic/166900-solved-php-include-in-loop-pulling-file-location-from-a-db/#findComment-880516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.