curious_george
01-29-2007, 11:02 AM
Well, what I have is very basic, but since I am not very good at PHP I am having a few problems. Most I have been able to figure out, but this one is giving me a headache. What I have is an HTML page consisting of 5 divs, one container, and the rest inside the container. Each of those divs has a php include in them. Here is a basic example:
<html>
<body>
<div id="container">
<div id="header">
<? include('header.php'); ?>
</div>
<div id="left">
<? include('left.php'); ?>
</div>
<div id="main">
<? include('main.php'); ?>
</div>
<div id="right">
<? include('right.php'); ?>
</div>
</div>
</body>
</html>
Like I said, very basic. Now, the problem is with my PHP in the right and left DIVs. The pages included in those DIVs have code that echos more divs, all of which contain php includes. I have done this before without any problems, but the files included in the inner DIVs were always text, so there was no problem. When I have the page include a page that contains php echo statements (echoing HTML) though, then only the first page gets included. Here is the code for left.php (the code for left and right.php are the same, just switched to access different tables):
<?php
include("dbinfo.inc.php");
mysql_connect(localhost,"$user","$password") or die("Could not connect");
@mysql_select_db($database) or die("The database is currently unavailable. Please try again later!");
$query=" SELECT * FROM site_left WHERE active = 0";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
for($i=0;$i<$num;$i++)
{
$title=mysql_result($result,$i,"title");
$place=mysql_result($result,$i,"place");
$active_left=mysql_result($result,$i,"active");
$path='site/'.$place;
if($active_left==0)
{
if (file_exists($path))
{
echo '<div class="tt">
</div>
<div class="mid">
<font size="5">'.$title.'</font>
</div>
<div class="tb">
</div>
<div class="mid">';
include($path);
echo '</div>
<div class="b">
</div>';
}
}
}
?>
Like I said, if the page saved in $path is all text then it displays all of the files, but when it contains php echo statements (echoing HTML) it only shows the first occurence. I created a few test pages to run through the script and they all had the same problem. Here is a basic test page that I tried to use:
<?php
include("dbinfo.inc.php");
mysql_connect(localhost,"$user","$password") or die("Could not connect");
@mysql_select_db($database) or die("The database is currently unavailable. Please try again later!");
$query=" SELECT * FROM members ORDER BY id DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
if($num<1)
{
die($num);
}
$end=10;
if($num<$end)
$end=$num;
echo "<b><u>10 Newest Members</u></b>";
for($i=0;$i<$end;$i++)
{
$mem=mysql_result($result,$i,"id");
echo "<br>".($i+1).". <a href='member.php?id=".$mem."'>";
$mem=mysql_result($result,$i,"user");
echo $mem."</a>";
}
?>
And then I also tried another page too, so that there would be two pages listed in the site_left DB table accessed in left.php, as shown above. I have yet to find a problem with the syntax, so I am not sure why the for-loop in left.php stops after the first instance, especillay since when I insert 5 text pages into the site_left table all 5 show up. Any ideas? Thanks in advance.
<html>
<body>
<div id="container">
<div id="header">
<? include('header.php'); ?>
</div>
<div id="left">
<? include('left.php'); ?>
</div>
<div id="main">
<? include('main.php'); ?>
</div>
<div id="right">
<? include('right.php'); ?>
</div>
</div>
</body>
</html>
Like I said, very basic. Now, the problem is with my PHP in the right and left DIVs. The pages included in those DIVs have code that echos more divs, all of which contain php includes. I have done this before without any problems, but the files included in the inner DIVs were always text, so there was no problem. When I have the page include a page that contains php echo statements (echoing HTML) though, then only the first page gets included. Here is the code for left.php (the code for left and right.php are the same, just switched to access different tables):
<?php
include("dbinfo.inc.php");
mysql_connect(localhost,"$user","$password") or die("Could not connect");
@mysql_select_db($database) or die("The database is currently unavailable. Please try again later!");
$query=" SELECT * FROM site_left WHERE active = 0";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
for($i=0;$i<$num;$i++)
{
$title=mysql_result($result,$i,"title");
$place=mysql_result($result,$i,"place");
$active_left=mysql_result($result,$i,"active");
$path='site/'.$place;
if($active_left==0)
{
if (file_exists($path))
{
echo '<div class="tt">
</div>
<div class="mid">
<font size="5">'.$title.'</font>
</div>
<div class="tb">
</div>
<div class="mid">';
include($path);
echo '</div>
<div class="b">
</div>';
}
}
}
?>
Like I said, if the page saved in $path is all text then it displays all of the files, but when it contains php echo statements (echoing HTML) it only shows the first occurence. I created a few test pages to run through the script and they all had the same problem. Here is a basic test page that I tried to use:
<?php
include("dbinfo.inc.php");
mysql_connect(localhost,"$user","$password") or die("Could not connect");
@mysql_select_db($database) or die("The database is currently unavailable. Please try again later!");
$query=" SELECT * FROM members ORDER BY id DESC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
if($num<1)
{
die($num);
}
$end=10;
if($num<$end)
$end=$num;
echo "<b><u>10 Newest Members</u></b>";
for($i=0;$i<$end;$i++)
{
$mem=mysql_result($result,$i,"id");
echo "<br>".($i+1).". <a href='member.php?id=".$mem."'>";
$mem=mysql_result($result,$i,"user");
echo $mem."</a>";
}
?>
And then I also tried another page too, so that there would be two pages listed in the site_left DB table accessed in left.php, as shown above. I have yet to find a problem with the syntax, so I am not sure why the for-loop in left.php stops after the first instance, especillay since when I insert 5 text pages into the site_left table all 5 show up. Any ideas? Thanks in advance.